From 4f801b422880999b4e72b860f21a5f967887ee94 Mon Sep 17 00:00:00 2001 From: kennytv Date: Sat, 14 Aug 2021 10:51:49 +0200 Subject: [PATCH] Fix 1.16->1.15 wolf anger Fixes #392 --- .../packets/EntityPackets1_14.java | 5 ++-- .../Protocol1_15_2To1_16.java | 2 +- .../packets/EntityPackets1_16.java | 29 +++++++++++++++++-- .../storage/WolfDataMaskStorage.java | 18 ++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/storage/WolfDataMaskStorage.java diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index e9e8746d..7ce687f5 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -320,10 +320,11 @@ public class EntityPackets1_14 extends LegacyEntityRewriter { private final ValueTransformer dimensionTransformer = new ValueTransformer(Type.STRING, Type.INT) { @Override - public Integer transform(PacketWrapper wrapper, String input) throws Exception { + public Integer transform(PacketWrapper wrapper, String input) { switch (input) { case "minecraft:the_nether": return -1; @@ -293,9 +296,31 @@ public class EntityPackets1_16 extends EntityRewriter { filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).cancel(8); filter().filterFamily(Entity1_16Types.ABSTRACT_ARROW).handler((event, meta) -> { if (event.index() >= 8) { - event.setIndex(event.index() + 1); // TODO is this right...? + event.setIndex(event.index() + 1); } }); + + filter().type(Entity1_16Types.WOLF).index(16).handler((event, meta) -> { + byte mask = meta.value(); + StoredEntityData data = tracker(event.user()).entityData(event.entityId()); + data.put(new WolfDataMaskStorage(mask)); + }); + + filter().type(Entity1_16Types.WOLF).index(20).handler((event, meta) -> { + StoredEntityData data = tracker(event.user()).entityDataIfPresent(event.entityId()); + byte previousMask = 0; + if (data != null) { + WolfDataMaskStorage wolfData = data.get(WolfDataMaskStorage.class); + if (wolfData != null) { + previousMask = wolfData.tameableMask(); + } + } + + int angerTime = meta.value(); + byte tameableMask = (byte) (angerTime > 0 ? previousMask | 2 : previousMask & -3); + event.createExtraMeta(new Metadata(16, MetaType1_14.Byte, tameableMask)); + event.cancel(); + }); } @Override diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/storage/WolfDataMaskStorage.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/storage/WolfDataMaskStorage.java new file mode 100644 index 00000000..c687ca6d --- /dev/null +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_15_2to1_16/storage/WolfDataMaskStorage.java @@ -0,0 +1,18 @@ +package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage; + +public final class WolfDataMaskStorage { + + private byte tameableMask; + + public WolfDataMaskStorage(byte tameableMask) { + this.tameableMask = tameableMask; + } + + public void setTameableMask(byte tameableMask) { + this.tameableMask = tameableMask; + } + + public byte tameableMask() { + return tameableMask; + } +}