use of com.github.steveice10.mc.protocol.data.game.chunk.Column in project DragonProxy by DragonetMC.
the class ChunkCache method update.
public void update(Position position, BlockState block) {
ChunkPos columnPos = new ChunkPos(position.getX() >> 4, position.getZ() >> 4);
// System.out.println("translateBlock Position " + position.toString());
if (chunkCache.containsKey(columnPos))
try {
Column column = chunkCache.get(columnPos);
BlockPosition blockPos = columnPos.getBlockInChunk(position.getX(), position.getY(), position.getZ());
Chunk chunk = column.getChunks()[position.getY() >> 4];
if (chunk != null)
chunk.getBlocks().set(blockPos.x, blockPos.y, blockPos.z, block);
} catch (java.lang.ArrayIndexOutOfBoundsException ex) {
this.session.getProxy().getLogger().info("update(" + position.toString() + ", " + block.toString() + ")) fail to get chunk " + (position.getX() >> 4) + "/" + (position.getY() >> 4) + "/" + (position.getZ() >> 4));
ex.printStackTrace();
}
// enqueue block update
}
use of com.github.steveice10.mc.protocol.data.game.chunk.Column in project DragonProxy by DragonetMC.
the class ChunkCache method getBlock.
public final ItemStack getBlock(Position position) {
ChunkPos columnPos = new ChunkPos(position.getX() >> 4, position.getZ() >> 4);
if (chunkCache.containsKey(columnPos))
try {
Column column = chunkCache.get(columnPos);
BlockPosition blockPos = columnPos.getBlockInChunk(position.getX(), position.getY(), position.getZ());
Chunk chunk = column.getChunks()[position.getY() >> 4];
if (chunk != null) {
BlockState block = chunk.getBlocks().get(blockPos.x, blockPos.y, blockPos.z);
return new ItemStack(block.getId(), 1, block.getData());
}
} catch (java.lang.ArrayIndexOutOfBoundsException ex) {
this.session.getProxy().getLogger().severe("(getBlock(" + position.toString() + ")) fail to get chunk " + (position.getX() >> 4) + "/" + (position.getY() >> 4) + "/" + (position.getZ() >> 4));
ex.printStackTrace();
}
return null;
}
use of com.github.steveice10.mc.protocol.data.game.chunk.Column in project DragonProxy by DragonetMC.
the class ChunkCache method translateChunk.
public final ChunkData translateChunk(int columnX, int columnZ) {
ChunkPos columnPos = new ChunkPos(columnX, columnZ);
if (chunkCache.containsKey(columnPos)) {
Column column = chunkCache.get(columnPos);
ChunkData chunk = new ChunkData();
chunk.sections = new Section[16];
for (int i = 0; i < 16; i++) chunk.sections[i] = new Section();
// Blocks
for (int y = 0; y < 256; y++) {
int cy = y >> 4;
Chunk c = null;
try {
c = column.getChunks()[cy];
} catch (Exception ex) {
DragonProxy.getInstance().getLogger().info("Chunk " + columnX + ", " + cy + ", " + columnZ + " not exist !");
}
if (c == null || c.isEmpty())
continue;
BlockStorage blocks = c.getBlocks();
for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) {
BlockState block = blocks.get(x, y & 0xF, z);
ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData());
Section section = chunk.sections[cy];
// Block id
section.blockIds[index(x, y, z)] = (byte) (entry.getId() & 0xFF);
// Data value
int i = dataIndex(x, y, z);
byte data = section.blockMetas[i];
int newValue = entry.getPEDamage().byteValue();
if ((y & 1) == 0)
data = (byte) ((data & 0xf0) | (newValue & 0x0f));
else
data = (byte) (((newValue & 0x0f) << 4) | (data & 0x0f));
section.blockMetas[i] = data;
}
}
// Blocks entities
try {
List<CompoundTag> blockEntities = new ArrayList<>();
for (int i = 0; i < column.getTileEntities().length; i++) {
CompoundTag peTag = ItemBlockTranslator.translateBlockEntityToPE(column.getTileEntities()[i]);
if (// filter non handled blocks entities
peTag != null)
blockEntities.add(peTag);
// else // debug
// DragonProxy.getInstance().getLogger().debug("NBT null for " + pc.getTileEntities()[i].toString());
}
chunk.blockEntities = NBTIO.write(blockEntities, ByteOrder.LITTLE_ENDIAN, true);
} catch (IOException ex) {
ex.printStackTrace();
}
chunk.encode();
return chunk;
}
// System.out.println("Chunk " + columnX + ", " + columnZ + " not in cache !!!!!!!!!!!!!");
return null;
}
use of com.github.steveice10.mc.protocol.data.game.chunk.Column in project DragonProxy by DragonetMC.
the class ChunkCache method translateBlock.
public final ItemEntry translateBlock(Position position) {
ChunkPos columnPos = new ChunkPos(position.getX() >> 4, position.getZ() >> 4);
if (chunkCache.containsKey(columnPos))
try {
Column column = chunkCache.get(columnPos);
BlockPosition blockPos = columnPos.getBlockInChunk(position.getX(), position.getY(), position.getZ());
Chunk chunk = column.getChunks()[position.getY() >> 4];
if (chunk != null) {
BlockState block = chunk.getBlocks().get(blockPos.x, blockPos.y, blockPos.z);
return ItemBlockTranslator.translateToPE(block.getId(), block.getData());
}
} catch (java.lang.ArrayIndexOutOfBoundsException ex) {
this.session.getProxy().getLogger().info("getBlock(" + position.toString() + ")) fail to get chunk " + (position.getX() >> 4) + "/" + (position.getY() >> 4) + "/" + (position.getZ() >> 4));
ex.printStackTrace();
}
return null;
}
Aggregations