use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17 in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_18 method registerPackets.
@Override
protected void registerPackets() {
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_18.DECLARE_RECIPES);
registerSetCooldown(ClientboundPackets1_18.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_18.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, Type.FLAT_VAR_INT_ITEM);
registerSetSlot1_17_1(ClientboundPackets1_18.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_18.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_18.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_18.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_18.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect id
map(Type.INT);
// Location
map(Type.POSITION1_14);
// Data
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
}
});
}
});
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_18.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
// Particle id
map(Type.INT);
// Override limiter
map(Type.BOOLEAN);
// X
map(Type.DOUBLE);
// Y
map(Type.DOUBLE);
// Z
map(Type.DOUBLE);
// Offset X
map(Type.FLOAT);
// Offset Y
map(Type.FLOAT);
// Offset Z
map(Type.FLOAT);
// Max speed
map(Type.FLOAT);
// Particle Count
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 3) {
// Block marker
int blockState = wrapper.read(Type.VAR_INT);
if (blockState == 7786) {
// Light block
wrapper.set(Type.INT, 0, 3);
} else {
// Else assume barrier block
wrapper.set(Type.INT, 0, 2);
}
return;
}
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
if (mappings.isBlockParticle(id)) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
int newId = protocol.getMappingData().getNewParticleId(id);
if (newId != id) {
wrapper.set(Type.INT, 0, newId);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_18.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
handler(wrapper -> {
final int id = wrapper.read(Type.VAR_INT);
final CompoundTag tag = wrapper.read(Type.NBT);
final int mappedId = BlockEntityIds.mappedId(id);
if (mappedId == -1) {
wrapper.cancel();
return;
}
final String identifier = protocol.getMappingData().blockEntities().get(id);
if (identifier == null) {
wrapper.cancel();
return;
}
// The 1.18 server doesn't include the id and positions (x, y, z) in the NBT anymore
// If those were the only fields on the block entity (e.g.: skull, bed), we'll receive a null NBT
// We initialize one and add the missing fields, so it can be handled correctly down the line
final CompoundTag newTag = tag == null ? new CompoundTag() : tag;
final Position pos = wrapper.get(Type.POSITION1_14, 0);
// The protocol converters downstream rely on this field, let's add it back
newTag.put("id", new StringTag("minecraft:" + identifier));
// Weird glitches happen with the 1.17 client and below if these fields are missing
// Some examples are block entity models becoming invisible (e.g.: signs, banners)
newTag.put("x", new IntTag(pos.x()));
newTag.put("y", new IntTag(pos.y()));
newTag.put("z", new IntTag(pos.z()));
handleSpawner(id, newTag);
wrapper.write(Type.UNSIGNED_BYTE, (short) mappedId);
wrapper.write(Type.NBT, newTag);
});
}
});
protocol.registerClientbound(ClientboundPackets1_18.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
final Chunk1_18Type chunkType = new Chunk1_18Type(tracker.currentWorldSectionHeight(), MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().size()), MathUtil.ceilLog2(tracker.biomesSent()));
final Chunk oldChunk = wrapper.read(chunkType);
final ChunkSection[] sections = oldChunk.getSections();
final BitSet mask = new BitSet(oldChunk.getSections().length);
final int[] biomeData = new int[sections.length * ChunkSection.BIOME_SIZE];
int biomeIndex = 0;
for (int j = 0; j < sections.length; j++) {
final ChunkSection section = sections[j];
// Write biome palette into biome array
final DataPalette biomePalette = section.palette(PaletteType.BIOMES);
for (int i = 0; i < ChunkSection.BIOME_SIZE; i++) {
biomeData[biomeIndex++] = biomePalette.idAt(i);
}
// Rewrite to empty section
if (section.getNonAirBlocksCount() == 0) {
sections[j] = null;
} else {
mask.set(j);
}
}
final List<CompoundTag> blockEntityTags = new ArrayList<>(oldChunk.blockEntities().size());
for (final BlockEntity blockEntity : oldChunk.blockEntities()) {
final String id = protocol.getMappingData().blockEntities().get(blockEntity.typeId());
if (id == null) {
// Shrug
continue;
}
final CompoundTag tag;
if (blockEntity.tag() != null) {
tag = blockEntity.tag();
handleSpawner(blockEntity.typeId(), tag);
} else {
tag = new CompoundTag();
}
blockEntityTags.add(tag);
tag.put("x", new IntTag((oldChunk.getX() << 4) + blockEntity.sectionX()));
tag.put("y", new IntTag(blockEntity.y()));
tag.put("z", new IntTag((oldChunk.getZ() << 4) + blockEntity.sectionZ()));
tag.put("id", new StringTag("minecraft:" + id));
}
final Chunk chunk = new BaseChunk(oldChunk.getX(), oldChunk.getZ(), true, false, mask, oldChunk.getSections(), biomeData, oldChunk.getHeightMap(), blockEntityTags);
wrapper.write(new Chunk1_17Type(tracker.currentWorldSectionHeight()), chunk);
// Create and send light packet first
final PacketWrapper lightPacket = wrapper.create(ClientboundPackets1_17_1.UPDATE_LIGHT);
lightPacket.write(Type.VAR_INT, chunk.getX());
lightPacket.write(Type.VAR_INT, chunk.getZ());
// Trust edges
lightPacket.write(Type.BOOLEAN, wrapper.read(Type.BOOLEAN));
// Sky light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
// Block light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
// Empty sky light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
// Empty block light mask
lightPacket.write(Type.LONG_ARRAY_PRIMITIVE, wrapper.read(Type.LONG_ARRAY_PRIMITIVE));
final int skyLightLength = wrapper.read(Type.VAR_INT);
lightPacket.write(Type.VAR_INT, skyLightLength);
for (int i = 0; i < skyLightLength; i++) {
lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, wrapper.read(Type.BYTE_ARRAY_PRIMITIVE));
}
final int blockLightLength = wrapper.read(Type.VAR_INT);
lightPacket.write(Type.VAR_INT, blockLightLength);
for (int i = 0; i < blockLightLength; i++) {
lightPacket.write(Type.BYTE_ARRAY_PRIMITIVE, wrapper.read(Type.BYTE_ARRAY_PRIMITIVE));
}
lightPacket.send(Protocol1_17_1To1_18.class);
});
}
});
protocol.cancelClientbound(ClientboundPackets1_18.SET_SIMULATION_DISTANCE);
}
use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_16_2.DECLARE_RECIPES);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerServerbound(ServerboundPackets1_17.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
protocol.registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.UNSIGNED_BYTE);
// Slot
map(Type.SHORT);
// Button
map(Type.BYTE);
// Action id - doesn't matter, as the sent out confirmation packet will be cancelled
handler(wrapper -> wrapper.write(Type.SHORT, (short) 0));
// Action
map(Type.VAR_INT);
handler(wrapper -> {
// Affected items - throw them away!
int length = wrapper.read(Type.VAR_INT);
for (int i = 0; i < length; i++) {
// Slot
wrapper.read(Type.SHORT);
wrapper.read(Type.FLAT_VAR_INT_ITEM);
}
// 1.17 clients send the then carried item, but 1.16 expects the clicked one
Item item = wrapper.read(Type.FLAT_VAR_INT_ITEM);
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 5 || action == 1) {
// Quick craft (= dragging / mouse movement while clicking on an empty slot)
// OR Quick move (= shift click to move a whole stack to the other inventory)
// The server always expects an empty item here
item = null;
} else {
// Use the item sent
handleItemToServer(item);
}
wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
});
}
});
protocol.registerClientbound(ClientboundPackets1_16_2.WINDOW_CONFIRMATION, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
short inventoryId = wrapper.read(Type.UNSIGNED_BYTE);
short confirmationId = wrapper.read(Type.SHORT);
boolean accepted = wrapper.read(Type.BOOLEAN);
if (!accepted) {
// Use the new ping packet to replace the removed acknowledgement, extra bit for fast dismissal
int id = (1 << 30) | (inventoryId << 16) | (confirmationId & 0xFFFF);
wrapper.user().get(InventoryAcknowledgements.class).addId(id);
PacketWrapper pingPacket = wrapper.create(ClientboundPackets1_17.PING);
pingPacket.write(Type.INT, id);
pingPacket.send(Protocol1_17To1_16_4.class);
}
wrapper.cancel();
});
}
});
// New pong packet
protocol.registerServerbound(ServerboundPackets1_17.PONG, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int id = wrapper.read(Type.INT);
// Check extra bit for fast dismissal
if ((id & (1 << 30)) != 0 && wrapper.user().get(InventoryAcknowledgements.class).removeId(id)) {
// Decode our requested inventory acknowledgement
short inventoryId = (short) ((id >> 16) & 0xFF);
short confirmationId = (short) (id & 0xFFFF);
PacketWrapper packet = wrapper.create(ServerboundPackets1_16_2.WINDOW_CONFIRMATION);
packet.write(Type.UNSIGNED_BYTE, inventoryId);
packet.write(Type.SHORT, confirmationId);
// Accept
packet.write(Type.BOOLEAN, true);
packet.sendToServer(Protocol1_17To1_16_4.class);
}
wrapper.cancel();
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17 in project ViaVersion by ViaVersion.
the class InventoryPackets method registerPackets.
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_17_1.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_17_1.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_17_1.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerSetSlot1_17_1(ClientboundPackets1_17_1.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_17_1.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipmentArray(ClientboundPackets1_17_1.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
protocol.registerClientbound(ClientboundPackets1_17_1.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect id
map(Type.INT);
// Location
map(Type.POSITION1_14);
// Data
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
int data = wrapper.get(Type.INT, 1);
if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_17_1.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
// Particle id
map(Type.INT);
// Override limiter
map(Type.BOOLEAN);
// X
map(Type.DOUBLE);
// Y
map(Type.DOUBLE);
// Z
map(Type.DOUBLE);
// Offset X
map(Type.FLOAT);
// Offset Y
map(Type.FLOAT);
// Offset Z
map(Type.FLOAT);
// Max speed
map(Type.FLOAT);
// Particle Count
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 2) {
// Barrier
// Block marker
wrapper.set(Type.INT, 0, 3);
wrapper.write(Type.VAR_INT, 7754);
return;
} else if (id == 3) {
// Light block
wrapper.write(Type.VAR_INT, 7786);
return;
}
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
if (mappings.isBlockParticle(id)) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) {
handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
}
int newId = protocol.getMappingData().getNewParticleId(id);
if (newId != id) {
wrapper.set(Type.INT, 0, newId);
}
});
}
});
new RecipeRewriter1_16(protocol).registerDefaultHandler(ClientboundPackets1_17_1.DECLARE_RECIPES);
registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
}
Aggregations