use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8 in project ViaVersion by ViaVersion.
the class ConnectionData method updateChunkSectionNeighbours.
public static void updateChunkSectionNeighbours(UserConnection user, int chunkX, int chunkZ, int chunkSectionY) {
for (int chunkDeltaX = -1; chunkDeltaX <= 1; chunkDeltaX++) {
for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) {
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0)
continue;
List<BlockChangeRecord1_8> updates = new ArrayList<>();
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) {
// Corner
for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
int blockPosX = chunkDeltaX == 1 ? 0 : 15;
int blockPosZ = chunkDeltaZ == 1 ? 0 : 15;
updateBlock(user, new Position(((chunkX + chunkDeltaX) << 4) + blockPosX, (short) blockY, ((chunkZ + chunkDeltaZ) << 4) + blockPosZ), updates);
}
} else {
for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
int xStart;
int xEnd;
int zStart;
int zEnd;
if (chunkDeltaX == 1) {
xStart = 0;
xEnd = 2;
zStart = 0;
zEnd = 16;
} else if (chunkDeltaX == -1) {
xStart = 14;
xEnd = 16;
zStart = 0;
zEnd = 16;
} else if (chunkDeltaZ == 1) {
xStart = 0;
xEnd = 16;
zStart = 0;
zEnd = 2;
} else {
xStart = 0;
xEnd = 16;
zStart = 14;
zEnd = 16;
}
for (int blockX = xStart; blockX < xEnd; blockX++) {
for (int blockZ = zStart; blockZ < zEnd; blockZ++) {
updateBlock(user, new Position(((chunkX + chunkDeltaX) << 4) + blockX, (short) blockY, ((chunkZ + chunkDeltaZ) << 4) + blockZ), updates);
}
}
}
}
if (!updates.isEmpty()) {
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.MULTI_BLOCK_CHANGE, null, user);
wrapper.write(Type.INT, chunkX + chunkDeltaX);
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));
try {
wrapper.send(Protocol1_13To1_12_2.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8 in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_16_2 method registerPackets.
@Override
protected void registerPackets() {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_16_2.UNLOCK_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
// Open
wrapper.passthrough(Type.BOOLEAN);
// Filter
wrapper.passthrough(Type.BOOLEAN);
// Furnace Open
wrapper.passthrough(Type.BOOLEAN);
// Filter furnace
wrapper.passthrough(Type.BOOLEAN);
// Blast furnace / smoker
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
wrapper.read(Type.BOOLEAN);
});
}
});
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16_2Type());
wrapper.write(new Chunk1_16Type(), chunk);
chunk.setIgnoreOldLightData(true);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
}
}
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
if (blockEntity != null) {
handleBlockEntity(blockEntity);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
handleBlockEntity(wrapper.passthrough(Type.NBT));
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
long chunkPosition = wrapper.read(Type.LONG);
// Ignore old light data
wrapper.read(Type.BOOLEAN);
int chunkX = (int) (chunkPosition >> 42);
int chunkY = (int) (chunkPosition << 44 >> 44);
int chunkZ = (int) (chunkPosition << 22 >> 42);
wrapper.write(Type.INT, chunkX);
wrapper.write(Type.INT, chunkZ);
BlockChangeRecord[] blockChangeRecord = wrapper.read(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecord);
for (int i = 0; i < blockChangeRecord.length; i++) {
BlockChangeRecord record = blockChangeRecord[i];
int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
// Relative y -> absolute y
blockChangeRecord[i] = new BlockChangeRecord1_8(record.getSectionX(), record.getY(chunkY), record.getSectionZ(), blockId);
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16_2.EFFECT, 1010, 2001);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
}
use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8 in project ViaVersion by ViaVersion.
the class ConnectionData method updateBlock.
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord1_8> records) {
int blockState = blockConnectionProvider.getBlockData(user, pos.x(), pos.y(), pos.z());
ConnectionHandler handler = getConnectionHandler(blockState);
if (handler == null)
return;
int newBlockState = handler.connect(user, pos, blockState);
records.add(new BlockChangeRecord1_8(pos.x() & 0xF, pos.y(), pos.z() & 0xF, newBlockState));
}
Aggregations