Fix 1.16->1.15 wolf anger

Fixes #392
This commit is contained in:
kennytv 2021-08-14 10:51:49 +02:00
parent 54dc05046f
commit 4f801b4228
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
4 changed files with 49 additions and 5 deletions

View File

@ -320,10 +320,11 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
wrapper.passthrough(Type.STRING); // Level Type
wrapper.read(Type.VAR_INT); // Read View Distance
//TODO Track client position
// Manually add position storage
int entitiyId = wrapper.get(Type.INT, 0);
/*int entitiyId = wrapper.get(Type.INT, 0);
StoredEntityData storedEntity = protocol.getEntityRewriter().tracker(wrapper.user()).entityData(entitiyId);
storedEntity.put(new EntityPositionStorage1_14());
storedEntity.put(new EntityPositionStorage1_14());*/
}
});
}

View File

@ -203,7 +203,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
user.put(new PlayerSneakStorage());
user.put(new WorldNameTracker());
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16Types.PLAYER));
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16Types.PLAYER, true));
}
@Override

View File

@ -20,12 +20,15 @@ package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.WorldNameTracker;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.storage.WolfDataMaskStorage;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
@ -44,7 +47,7 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
private final ValueTransformer<String, Integer> dimensionTransformer = new ValueTransformer<String, Integer>(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<Protocol1_15_2To1_16> {
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

View File

@ -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;
}
}