use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14 in project ViaBackwards by ViaVersion.
the class BlockItemPackets1_15 method registerPackets.
@Override
protected void registerPackets() {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
new RecipeRewriter1_14(protocol).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Chunk chunk = wrapper.read(new Chunk1_15Type());
wrapper.write(new Chunk1_14Type(), chunk);
if (chunk.isFullChunk()) {
int[] biomeData = chunk.getBiomeData();
int[] newBiomeData = new int[256];
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
int x = j << 2;
int z = i << 2;
int newIndex = z << 4 | x;
int oldIndex = i << 2 | j;
int biome = biomeData[oldIndex];
for (int k = 0; k < 4; k++) {
int offX = newIndex + (k << 4);
for (int l = 0; l < 4; l++) {
newBiomeData[offX + l] = biome;
}
}
}
}
chunk.setBiomeData(newBiomeData);
}
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);
int newId = protocol.getMappingData().getNewBlockStateId(old);
section.setPaletteEntry(j, newId);
}
}
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
protocol.registerClientbound(ClientboundPackets1_15.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Particle ID
map(Type.INT);
// 1 - Long Distance
map(Type.BOOLEAN);
// 2 - X
map(Type.DOUBLE, Type.FLOAT);
// 3 - Y
map(Type.DOUBLE, Type.FLOAT);
// 4 - Z
map(Type.DOUBLE, Type.FLOAT);
// 5 - Offset X
map(Type.FLOAT);
// 6 - Offset Y
map(Type.FLOAT);
// 7 - Offset Z
map(Type.FLOAT);
// 8 - Particle Data
map(Type.FLOAT);
// 9 - Particle Count
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.INT, 0);
if (id == 3 || id == 23) {
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) {
Item item = handleItemToClient(wrapper.read(Type.FLAT_VAR_INT_ITEM));
wrapper.write(Type.FLAT_VAR_INT_ITEM, item);
}
int mappedId = protocol.getMappingData().getNewParticleId(id);
if (id != mappedId) {
wrapper.set(Type.INT, 0, mappedId);
}
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14 in project ViaBackwards by ViaVersion.
the class Protocol1_15_2To1_16 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR);
translatableRewriter.registerCombatEvent(ClientboundPackets1_16.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_16.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_16.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_16.TITLE);
translatableRewriter.registerPing();
new CommandRewriter1_16(this).registerDeclareCommands(ClientboundPackets1_16.DECLARE_COMMANDS);
(blockItemPackets = new BlockItemPackets1_16(this)).register();
entityRewriter.register();
registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
String original = wrapper.passthrough(Type.STRING);
JsonObject object = GsonUtil.getGson().fromJson(original, JsonObject.class);
JsonElement description = object.get("description");
if (description == null)
return;
translatableRewriter.processText(description);
wrapper.set(Type.STRING, 0, object.toString());
});
}
});
registerClientbound(ClientboundPackets1_16.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
map(Type.BYTE);
// Sender
map(Type.UUID, Type.NOTHING);
}
});
registerClientbound(ClientboundPackets1_16.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.VAR_INT);
// Window Type
map(Type.VAR_INT);
handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
handler(wrapper -> {
int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType == 20) {
// Smithing table
// Open anvil inventory
wrapper.set(Type.VAR_INT, 1, 7);
} else if (windowType > 20) {
wrapper.set(Type.VAR_INT, 1, --windowType);
}
});
}
});
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_SOUND);
// Login success
registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Transform int array to plain string
UUID uuid = wrapper.read(Type.UUID_INT_ARRAY);
wrapper.write(Type.STRING, uuid.toString());
});
}
});
new TagRewriter(this).register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_16.STATISTICS);
registerServerbound(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// player id
wrapper.passthrough(Type.VAR_INT);
int action = wrapper.passthrough(Type.VAR_INT);
if (action == 0) {
wrapper.user().get(PlayerSneakStorage.class).setSneaking(true);
} else if (action == 1) {
wrapper.user().get(PlayerSneakStorage.class).setSneaking(false);
}
});
}
});
registerServerbound(ServerboundPackets1_14.INTERACT_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Entity Id
wrapper.passthrough(Type.VAR_INT);
int action = wrapper.passthrough(Type.VAR_INT);
if (action == 0 || action == 2) {
if (action == 2) {
// Location
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.FLOAT);
}
// Hand
wrapper.passthrough(Type.VAR_INT);
}
// New boolean: Whether the client is sneaking
wrapper.write(Type.BOOLEAN, wrapper.user().get(PlayerSneakStorage.class).isSneaking());
});
}
});
registerServerbound(ServerboundPackets1_14.PLAYER_ABILITIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
byte flags = wrapper.read(Type.BYTE);
// Only take the isFlying value (everything else has been removed and wasn't used anyways)
flags &= 2;
wrapper.write(Type.BYTE, flags);
wrapper.read(Type.FLOAT);
wrapper.read(Type.FLOAT);
});
}
});
cancelServerbound(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
}
use of com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14 in project ViaVersion by ViaVersion.
the class Protocol1_14To1_13_2 method registerPackets.
@Override
protected void registerPackets() {
metadataRewriter.register();
itemRewriter.register();
EntityPackets.register(this);
WorldPackets.register(this);
PlayerPackets.register(this);
new SoundRewriter(this).registerSound(ClientboundPackets1_13.SOUND);
new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
ComponentRewriter componentRewriter = new ComponentRewriter1_14(this);
componentRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT_MESSAGE);
CommandRewriter1_14 commandRewriter = new CommandRewriter1_14(this);
commandRewriter.registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS);
registerClientbound(ClientboundPackets1_13.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.read(Type.VAR_INT);
// block tags
wrapper.write(Type.VAR_INT, blockTagsSize + 6);
for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blockIds.length; j++) {
blockIds[j] = getMappingData().getNewBlockId(blockIds[j]);
}
}
// Minecraft crashes if we not send signs tags
wrapper.write(Type.STRING, "minecraft:signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewBlockId(150), getMappingData().getNewBlockId(155) });
wrapper.write(Type.STRING, "minecraft:wall_signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewBlockId(155) });
wrapper.write(Type.STRING, "minecraft:standing_signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewBlockId(150) });
// Fences and walls tags - used for block connections
wrapper.write(Type.STRING, "minecraft:fences");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 189, 248, 472, 473, 474, 475 });
wrapper.write(Type.STRING, "minecraft:walls");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 271, 272 });
wrapper.write(Type.STRING, "minecraft:wooden_fences");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 189, 472, 473, 474, 475 });
int itemTagsSize = wrapper.read(Type.VAR_INT);
// item tags
wrapper.write(Type.VAR_INT, itemTagsSize + 2);
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < itemIds.length; j++) {
itemIds[j] = getMappingData().getNewItemId(itemIds[j]);
}
}
// Should fix fuel shift clicking
wrapper.write(Type.STRING, "minecraft:signs");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { getMappingData().getNewItemId(541) });
// Arrows tag (used by bow)
wrapper.write(Type.STRING, "minecraft:arrows");
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[] { 526, 825, 826 });
// fluid tags
int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
}
// new entity tags - do we need to send this?
wrapper.write(Type.VAR_INT, 0);
}
});
}
});
// Set Difficulty packet added in 19w11a
cancelServerbound(ServerboundPackets1_14.SET_DIFFICULTY);
// Lock Difficulty packet added in 19w11a
cancelServerbound(ServerboundPackets1_14.LOCK_DIFFICULTY);
// Unknown packet added in 19w13a
cancelServerbound(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
}
Aggregations