cn.nukkit.level.generator.SimpleChunkManager Maven / Gradle / Ivy
package cn.nukkit.level.generator;
import cn.nukkit.api.DeprecationDetails;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.blockstate.BlockState;
import cn.nukkit.level.ChunkManager;
import cn.nukkit.level.format.FullChunk;
/**
* @author MagicDroidX (Nukkit Project)
*/
public abstract class SimpleChunkManager implements ChunkManager {
protected long seed;
public SimpleChunkManager(long seed) {
this.seed = seed;
}
@Override
public int getBlockIdAt(int x, int y, int z) {
return getBlockIdAt(x, y, z, 0);
}
@PowerNukkitOnly
@Override
public int getBlockIdAt(int x, int y, int z, int layer) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
return chunk.getBlockId(x & 0xf, ensureY(y, chunk), z & 0xf, layer);
}
return 0;
}
@PowerNukkitOnly
@Override
public BlockState getBlockStateAt(int x, int y, int z, int layer) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
return chunk.getBlockState(x & 0xf, ensureY(y, chunk), z & 0xf, layer);
}
return BlockState.AIR;
}
@Override
public void setBlockIdAt(int x, int y, int z, int id) {
setBlockIdAt(x, y, z, 0, id);
}
@PowerNukkitOnly
@Override
public void setBlockIdAt(int x, int y, int z, int layer, int id) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
chunk.setBlockId(x & 0xf, ensureY(y, chunk), z & 0xf, layer, id);
}
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@Override
public void setBlockAt(int x, int y, int z, int id, int data) {
setBlockAtLayer(x, y, z, 0, id, data);
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@PowerNukkitOnly
@Override
public boolean setBlockAtLayer(int x, int y, int z, int layer, int id, int data) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
return chunk.setBlockAtLayer(x & 0xf, ensureY(y, chunk), z & 0xf, layer, id, data);
}
return false;
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@Override
public void setBlockFullIdAt(int x, int y, int z, int fullId) {
setBlockFullIdAt(x, y, z, 0, fullId);
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@PowerNukkitOnly
@Override
public void setBlockFullIdAt(int x, int y, int z, int layer, int fullId) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
chunk.setFullBlockId(x & 0xf, ensureY(y, chunk), z & 0xf, layer, fullId);
}
}
@PowerNukkitOnly
@Since("1.4.0.0-PN")
@Override
public boolean setBlockStateAt(int x, int y, int z, int layer, BlockState state) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
return chunk.setBlockStateAtLayer(x & 0xf, ensureY(y, chunk), z & 0xf, layer, state);
}
return false;
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@Override
public int getBlockDataAt(int x, int y, int z) {
return getBlockDataAt(x, y, z, 0);
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@PowerNukkitOnly
@Override
public int getBlockDataAt(int x, int y, int z, int layer) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
return chunk.getBlockData(x & 0xf, ensureY(y, chunk), z & 0xf, layer);
}
return 0;
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@Override
public void setBlockDataAt(int x, int y, int z, int data) {
setBlockDataAt(x, y, z, data, 0);
}
@Deprecated
@DeprecationDetails(reason = "The meta is limited to 32 bits", since = "1.4.0.0-PN")
@PowerNukkitOnly
@Override
public void setBlockDataAt(int x, int y, int z, int layer, int data) {
FullChunk chunk = this.getChunk(x >> 4, z >> 4);
if (chunk != null) {
chunk.setBlockData(x & 0xf, ensureY(y, chunk), z & 0xf, layer, data);
}
}
@Override
public void setChunk(int chunkX, int chunkZ) {
this.setChunk(chunkX, chunkZ, null);
}
@Override
public long getSeed() {
return seed;
}
public void setSeed(long seed) {
this.seed = seed;
}
public void cleanChunks(long seed) {
this.seed = seed;
}
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
private int ensureY(final int y, final FullChunk chunk) {
if (chunk.isOverWorld()) {
return Math.max(Math.min(y, 319), -64);
} else {
return y & 0xff;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy