From aca265956f69bce4147fadf287913e1b1199123c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Mon, 27 Jan 2020 18:43:03 +0100 Subject: [PATCH] Handle 1.14 zombies/skeletons holding up arms --- .../api/entities/meta/MetaHandlerEvent.java | 52 +++++++++++++++---- .../packets/EntityPackets1_14.java | 16 ++++++ 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java index eca20d4e..c9feecbb 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/meta/MetaHandlerEvent.java @@ -10,8 +10,6 @@ package nl.matsv.viabackwards.api.entities.meta; -import lombok.Getter; -import lombok.RequiredArgsConstructor; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import us.myles.ViaVersion.api.data.UserConnection; @@ -19,10 +17,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import java.util.ArrayList; import java.util.List; -import java.util.Optional; -@Getter -@RequiredArgsConstructor public class MetaHandlerEvent { private final UserConnection user; private final EntityTracker.StoredEntity entity; @@ -31,15 +26,25 @@ public class MetaHandlerEvent { private final MetaStorage storage; private List extraData; + public MetaHandlerEvent(UserConnection user, EntityTracker.StoredEntity entity, int index, Metadata data, MetaStorage storage) { + this.user = user; + this.entity = entity; + this.index = index; + this.data = data; + this.storage = storage; + } + public boolean hasData() { return data != null; } - public Optional getMetaByIndex(int index) { - for (Metadata meta : storage.getMetaDataList()) - if (index == meta.getId()) - return Optional.of(meta); - return Optional.empty(); + public Metadata getMetaByIndex(int index) { + for (Metadata meta : storage.getMetaDataList()) { + if (index == meta.getId()) { + return meta; + } + } + return null; } public void clearExtraData() { @@ -49,4 +54,31 @@ public class MetaHandlerEvent { public void createMeta(Metadata metadata) { (extraData != null ? extraData : (extraData = new ArrayList<>())).add(metadata); } + + public UserConnection getUser() { + return user; + } + + public EntityTracker.StoredEntity getEntity() { + return entity; + } + + public int getIndex() { + return index; + } + + public Metadata getData() { + return data; + } + + public MetaStorage getStorage() { + return storage; + } + + /** + * May be null, use {@link #createMeta(Metadata)} for adding metadata. + */ + public List getExtraData() { + return extraData; + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index 5c499206..a523becc 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -437,6 +437,22 @@ public class EntityPackets1_14 extends EntityRewriter { registerMetaHandler().filter(Entity1_14Types.EntityType.ZOMBIE_VILLAGER, 18).handle(villagerDataHandler); registerMetaHandler().filter(Entity1_14Types.EntityType.VILLAGER, 16).handle(villagerDataHandler); + // Holding arms up - from bitfield into own boolean + registerMetaHandler().filter(Entity1_14Types.EntityType.ABSTRACT_SKELETON, true, 13).handle(e -> { + byte value = (byte) e.getData().getValue(); + if ((value & 4) != 0) { + e.createMeta(new Metadata(14, MetaType1_13_2.Boolean, true)); + } + return e.getData(); + }); + registerMetaHandler().filter(Entity1_14Types.EntityType.ZOMBIE, true, 13).handle(e -> { + byte value = (byte) e.getData().getValue(); + if ((value & 4) != 0) { + e.createMeta(new Metadata(16, MetaType1_13_2.Boolean, true)); + } + return e.getData(); + }); + registerMetaHandler().filter(Entity1_14Types.EntityType.ZOMBIE, true).handle(e -> { Metadata meta = e.getData(); int index = e.getIndex();