From b2352105e6159857e3f592dba536dbced09c8ce1 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 21 Apr 2019 15:34:23 -0300 Subject: [PATCH 1/4] Handle new attack mode flag in insentient --- .../MetadataRewriter.java | 26 ++++++++++++++++--- .../storage/EntityTracker.java | 11 ++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java index 5bfdae0bf..a5cb3dc46 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java @@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets; +import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker; import java.util.ArrayList; import java.util.List; @@ -22,6 +23,8 @@ public class MetadataRewriter { try { metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID())); + EntityTracker tracker = connection.get(EntityTracker.class); + if (metadata.getMetaType() == MetaType1_14.Slot) { InventoryPackets.toClient((Item) metadata.getValue()); } else if (metadata.getMetaType() == MetaType1_14.BlockID) { @@ -42,6 +45,14 @@ public class MetadataRewriter { metadata.setId(metadata.getId() + 1); } + if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) { + if (metadata.getId() == 13) { + tracker.setInsentientData(entityId, (byte) ((((Number)metadata.getValue()).byteValue() & ~0x4) + | (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata + metadata.setValue(tracker.getInsentientData(entityId)); + } + } + if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) { if (metadata.getId() == 10) { // New block format @@ -91,11 +102,17 @@ public class MetadataRewriter { } } else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) { if (metadata.getId() == 12) { - metadatas.remove(metadata); // TODO "Is swinging arms", maybe moved to pos / entity status + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking + metadatas.remove(metadata); // "Is swinging arms" + metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); } } else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) { if (metadata.getId() == 16) { - metadatas.remove(metadata); // TODO "Are hands held up", maybe moved to pos / entity status + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking + metadatas.remove(metadata); // "Are hands held up" + metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); } else if (metadata.getId() > 16) { metadata.setId(metadata.getId() - 1); } @@ -108,7 +125,10 @@ public class MetadataRewriter { if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) { if (metadata.getId() == 14) { - metadatas.remove(metadata); // TODO "Has target (aggressive state)", maybe moved to pos / entity status + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking + metadatas.remove(metadata); // "Has target (aggressive state)" + metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/storage/EntityTracker.java index 4e752ca25..3a09cf2d6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/storage/EntityTracker.java @@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap; public class EntityTracker extends StoredObject { private final Map clientEntityTypes = new ConcurrentHashMap<>(); + private final Map insentientData = new ConcurrentHashMap<>(); @Getter @Setter private int latestTradeWindowId; @@ -23,12 +24,22 @@ public class EntityTracker extends StoredObject { public void removeEntity(int entityId) { clientEntityTypes.remove(entityId); + insentientData.remove(entityId); } public void addEntity(int entityId, UUID uuid, Entity1_14Types.EntityType type) { clientEntityTypes.put(entityId, type); } + public byte getInsentientData(int entity) { + Byte val = insentientData.get(entity); + return val == null ? 0 : val; + } + + public void setInsentientData(int entity, byte value) { + insentientData.put(entity, value); + } + public boolean has(int entityId) { return clientEntityTypes.containsKey(entityId); } From 3a4db0a6750cd71893c20f024556b866e10fbb67 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 21 Apr 2019 15:57:40 -0300 Subject: [PATCH 2/4] fixed --- .../protocols/protocol1_14to1_13_2/MetadataRewriter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java index a5cb3dc46..330ee6887 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java @@ -101,7 +101,7 @@ public class MetadataRewriter { metadata.setMetaType(MetaType1_14.OptVarInt); } } else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) { - if (metadata.getId() == 12) { + if (metadata.getId() == 14) { tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking metadatas.remove(metadata); // "Is swinging arms" @@ -126,7 +126,7 @@ public class MetadataRewriter { if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) { if (metadata.getId() == 14) { tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) - | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking + | (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking metadatas.remove(metadata); // "Has target (aggressive state)" metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); } From 8b5f6d1e67bbe62d37e281abf7a14e8b4272f17e Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 21 Apr 2019 16:32:59 -0300 Subject: [PATCH 3/4] fixed some metadata --- .../protocols/protocol1_14to1_13_2/MetadataRewriter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java index 330ee6887..b73c0163b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java @@ -86,13 +86,13 @@ public class MetadataRewriter { metadata.setMetaType(MetaType1_14.VillagerData); } } else if (type.is(Entity1_14Types.EntityType.ZOMBIE_VILLAGER)) { - if (metadata.getId() == 19) { + if (metadata.getId() == 18) { // plains metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0)); metadata.setMetaType(MetaType1_14.VillagerData); } - } else if (type.isOrHasParent(Entity1_14Types.EntityType.ARROW)) { - if (metadata.getId() >= 9) { + } else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ARROW)) { + if (metadata.getId() >= 9) { // New piercing metadata.setId(metadata.getId() + 1); } } else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) { @@ -134,7 +134,7 @@ public class MetadataRewriter { // TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a if (type.is(Entity1_14Types.EntityType.WITCH) || type.is(Entity1_14Types.EntityType.RAVAGER) || type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) { - if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean with id 14 + if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14 metadata.setId(metadata.getId() + 1); } } From 4eb69eac662f09d7757bb2dcad6154aaf1341ae5 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 21 Apr 2019 16:50:41 -0300 Subject: [PATCH 4/4] Run zombie rewrite before zombie villager rewrite --- .../MetadataRewriter.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java index b73c0163b..c136c02f6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_14to1_13_2/MetadataRewriter.java @@ -53,6 +53,16 @@ public class MetadataRewriter { } } + if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) { + if (metadata.getId() == 16) { + tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) + | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking + metadatas.remove(metadata); // "Are hands held up" + metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); + } else if (metadata.getId() > 16) { + metadata.setId(metadata.getId() - 1); + } + } if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) { if (metadata.getId() == 10) { // New block format @@ -107,15 +117,6 @@ public class MetadataRewriter { metadatas.remove(metadata); // "Is swinging arms" metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); } - } else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) { - if (metadata.getId() == 16) { - tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) - | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking - metadatas.remove(metadata); // "Are hands held up" - metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId))); - } else if (metadata.getId() > 16) { - metadata.setId(metadata.getId() - 1); - } } else if (type.is(Entity1_14Types.EntityType.AREA_EFFECT_CLOUD)) { if (metadata.getId() == 10) { Particle particle = (Particle) metadata.getValue();