From 9e4718abc3fad5673b48ed47bacc16a0512ff4d0 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 9 Dec 2020 11:55:56 +0100 Subject: [PATCH] Handle new particles (untested), warn for custom world height --- .../packets/BlockItemPackets1_17.java | 35 +++++++++++++++++-- .../packets/EntityPackets1_17.java | 29 +++++++++++++-- .../data/mapping-1.16.2to1.17.json | 4 +-- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java index 678c18a5..a30f1633 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/BlockItemPackets1_17.java @@ -53,10 +53,39 @@ public class BlockItemPackets1_17 extends nl.matsv.viabackwards.api.rewriters.It } }); - //TODO vibration, dust_color_transition data - itemRewriter.registerSpawnParticle(ClientboundPackets1_17.SPAWN_PARTICLE, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); + protocol.registerOutgoing(ClientboundPackets1_17.SPAWN_PARTICLE, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // Particle Id + map(Type.BOOLEAN); // Long distance + map(Type.DOUBLE); // X + map(Type.DOUBLE); // Y + map(Type.DOUBLE); // Z + map(Type.FLOAT); // Offset X + map(Type.FLOAT); // Offset Y + map(Type.FLOAT); // Offset Z + map(Type.FLOAT); // Particle data + map(Type.INT); // Particle count + handler(wrapper -> { + int id = wrapper.get(Type.INT, 0); + if (id == 15) { + // Dust color transition -> Dust + wrapper.passthrough(Type.DOUBLE); // R + wrapper.passthrough(Type.DOUBLE); // G + wrapper.passthrough(Type.DOUBLE); // B + wrapper.passthrough(Type.FLOAT); // Scale - //TODO possibly have to check: player digging, block break animation, block entity data, block action, + wrapper.read(Type.DOUBLE); // R + wrapper.read(Type.DOUBLE); // G + wrapper.read(Type.DOUBLE); // B + } else if (id == 36) { + // Vibration signal - no nice mapping possible without tracking entity positions and doing particle tasks + wrapper.cancel(); + } + }); + handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM, Type.DOUBLE)); + } + }); // The Great Shrunkening // Some chunk sections will be lost ¯\_(ツ)_/¯ diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java index 55e92713..094ca65a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_16_4to1_17/packets/EntityPackets1_17.java @@ -1,5 +1,6 @@ package nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.packets; +import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17; import us.myles.ViaVersion.api.entities.Entity1_16_2Types; @@ -12,8 +13,11 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.Particle; import us.myles.ViaVersion.api.type.types.version.Types1_14; +import us.myles.ViaVersion.api.type.types.version.Types1_17; import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.ClientboundPackets1_17; import us.myles.viaversion.libs.gson.JsonElement; +import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import us.myles.viaversion.libs.opennbt.tag.builtin.IntTag; public class EntityPackets1_17 extends EntityRewriter { @@ -29,7 +33,7 @@ public class EntityPackets1_17 extends EntityRewriter { registerExtraTracker(ClientboundPackets1_17.SPAWN_PAINTING, Entity1_16_2Types.EntityType.PAINTING); registerExtraTracker(ClientboundPackets1_17.SPAWN_PLAYER, Entity1_16_2Types.EntityType.PLAYER); registerEntityDestroy(ClientboundPackets1_17.DESTROY_ENTITIES); - registerMetadataRewriter(ClientboundPackets1_17.ENTITY_METADATA, Types1_14.METADATA_LIST); + registerMetadataRewriter(ClientboundPackets1_17.ENTITY_METADATA, Types1_17.METADATA_LIST, Types1_14.METADATA_LIST); protocol.registerOutgoing(ClientboundPackets1_17.JOIN_GAME, new PacketRemapper() { @Override public void registerMap() { @@ -48,6 +52,7 @@ public class EntityPackets1_17 extends EntityRewriter { }); handler(getTrackerHandler(Entity1_16_2Types.EntityType.PLAYER, Type.INT)); handler(getWorldDataTracker(1)); + handler(wrapper -> warnForExtendedHeight(wrapper.get(Type.NBT, 1))); } }); protocol.registerOutgoing(ClientboundPackets1_17.RESPAWN, new PacketRemapper() { @@ -55,6 +60,7 @@ public class EntityPackets1_17 extends EntityRewriter { public void registerMap() { map(Type.NBT); // Dimension data handler(getWorldDataTracker(0)); + handler(wrapper -> warnForExtendedHeight(wrapper.get(Type.NBT, 0))); } }); } @@ -64,6 +70,7 @@ public class EntityPackets1_17 extends EntityRewriter { registerMetaHandler().handle(e -> { Metadata meta = e.getData(); MetaType type = meta.getMetaType(); + meta.setMetaType(MetaType1_14.byId(type.getTypeID())); if (type == MetaType1_14.Slot) { meta.setValue(protocol.getBlockItemPackets().handleItemToClient((Item) meta.getValue())); } else if (type == MetaType1_14.BlockID) { @@ -74,7 +81,17 @@ public class EntityPackets1_17 extends EntityRewriter { //protocol.getTranslatableRewriter().processText(text); //TODO } } else if (type == MetaType1_14.PARTICLE) { - rewriteParticle((Particle) meta.getValue()); + Particle particle = (Particle) meta.getValue(); + if (particle.getId() == 15) { + // Remove target color values 4-6 + particle.getArguments().subList(4, 7).clear(); + } else if (particle.getId() == 36) { + // Vibration signal - no nice mapping possible without tracking entity positions and doing particle tasks + particle.setId(0); + particle.getArguments().clear(); + } + + rewriteParticle(particle); } return meta; }); @@ -92,4 +109,12 @@ public class EntityPackets1_17 extends EntityRewriter { protected EntityType getTypeFromId(int typeId) { return Entity1_16_2Types.getTypeFromId(typeId); } + + private void warnForExtendedHeight(CompoundTag tag) { + IntTag minY = tag.get("min_y"); + IntTag height = tag.get("min_y"); + if (minY.getValue() != 0 || height.getValue() != 256) { + ViaBackwards.getPlatform().getLogger().severe("Custom worlds heights are NOT SUPPORTED for 1.16 players and older and may lead to errors!"); + } + } } diff --git a/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json b/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json index be173996..8bcb4486 100644 --- a/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json +++ b/core/src/main/resources/assets/viabackwards/data/mapping-1.16.2to1.17.json @@ -1012,7 +1012,7 @@ "falling_dripstone_lava": "falling_lava", "dripping_dripstone_water": "dripping_water", "falling_dripstone_water": "falling_water", - "vibration": "", - "dust_color_transition": "" + "dust_color_transition": "dust", + "vibration": "" } } \ No newline at end of file