From 4493f1c3a6a4d217aa6c7017aa81ff721f7d5eca Mon Sep 17 00:00:00 2001 From: Marco Neuhaus Date: Mon, 20 May 2019 21:51:45 +0200 Subject: [PATCH] fix spawn object --- .../api/entities/types/EntityType1_13.java | 7 ++++ .../api/entities/types/EntityType1_14.java | 1 + .../Protocol1_13_2To1_14.java | 2 +- .../packets/EntityPackets1_14.java | 33 +++++++++++-------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_13.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_13.java index 3b7b1a95..d5a1c93e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_13.java @@ -307,5 +307,12 @@ public class EntityType1_13 { return output.map(ObjectType::getType); } + + public static Optional fromEntityType(EntityType type){ + for (ObjectType ent : ObjectType.values()) + if (ent.getType() == type) + return Optional.of(ent); + return Optional.empty(); + } } } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_14.java b/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_14.java index df97e3a1..3ea747ea 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_14.java @@ -59,6 +59,7 @@ public class EntityType1_14 { CHICKEN(8, ABSTRACT_ANIMAL), COW(10, ABSTRACT_ANIMAL), MOOSHROOM(49, COW), + PANDA(52, ABSTRACT_INSENTIENT), PIG(54, ABSTRACT_ANIMAL), POLAR_BEAR(57, ABSTRACT_ANIMAL), RABBIT(59, ABSTRACT_ANIMAL), diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java index 6c29383f..5bccd61a 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/Protocol1_13_2To1_14.java @@ -238,7 +238,7 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol { registerIncoming(State.PLAY, 0x11, 0x10); // r registerIncoming(State.PLAY, 0x12, 0x11); // r registerIncoming(State.PLAY, 0x13, 0x12); // r - registerIncoming(State.PLAY, 0x14, 0xF0); // r + registerIncoming(State.PLAY, 0x14, 0x0F); // r registerIncoming(State.PLAY, 0x15, 0x13); // r registerIncoming(State.PLAY, 0x16, 0x14); // r registerIncoming(State.PLAY, 0x17, 0x15); // r 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 5bba4d29..39cf3c1e 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 @@ -2,7 +2,6 @@ package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.packets; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.entities.storage.EntityData; -import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.entities.storage.MetaStorage; import nl.matsv.viabackwards.api.entities.types.AbstractEntityType; import nl.matsv.viabackwards.api.entities.types.EntityType1_13; @@ -12,24 +11,17 @@ import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPack import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14; import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.EntityTypeMapping; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.VillagerData; import us.myles.ViaVersion.api.minecraft.item.Item; -import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13_2; -import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.api.type.types.version.Types1_12; import us.myles.ViaVersion.api.type.types.version.Types1_13_2; import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.MetadataRewriter; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -import java.util.LinkedList; -import java.util.List; import java.util.Optional; public class EntityPackets1_14 extends EntityRewriter { @@ -68,10 +60,9 @@ public class EntityPackets1_14 extends EntityRewriter { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - Optional type = EntityType1_13.ObjectType.findById(EntityTypeMapping.getObjectId( - EntityTypeMapping.getOldId(wrapper.get(Type.BYTE, 0)) - .orElse(0) - ).orElse(0)); + int id = wrapper.get(Type.BYTE, 0); + EntityType1_13.EntityType entityType = EntityType1_13.getTypeFromId(EntityTypeMapping.getOldId(id).orElse(id), false); + Optional type = EntityType1_13.ObjectType.fromEntityType(entityType); if (type.isPresent()) { wrapper.set(Type.BYTE, 0, (byte) type.get().getId()); } @@ -228,7 +219,7 @@ public class EntityPackets1_14 extends EntityRewriter { @Override public void handle(PacketWrapper wrapper) throws Exception { for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) - wrapper.user().get(EntityTracker.class).get(protocol).removeEntity(entity); + getEntityTracker(wrapper.user()).removeEntity(entity); } }); } @@ -292,10 +283,24 @@ public class EntityPackets1_14 extends EntityRewriter { @Override protected void registerRewrites() { regEntType(EntityType1_14.EntityType.CAT, EntityType1_14.EntityType.OCELOT).mobName("Cat").spawnMetadata(e -> { - e.add(new Metadata(13, MetaType1_13_2.Byte, (byte) 0x4)); // Tamed cat + // e.add(new Metadata(13, MetaType1_13_2.Byte, (byte) 0x4)); // Tamed cat }); regEntType(EntityType1_14.EntityType.OCELOT, EntityType1_14.EntityType.OCELOT).mobName("Ocelot"); regEntType(EntityType1_14.EntityType.TRADER_LLAMA, EntityType1_14.EntityType.LLAMA).mobName("Trader Llama"); + regEntType(EntityType1_14.EntityType.FOX, EntityType1_14.EntityType.WOLF).mobName("Fox"); + regEntType(EntityType1_14.EntityType.PANDA, EntityType1_14.EntityType.POLAR_BEAR).mobName("Panda"); + + registerMetaHandler().filter(EntityType1_14.EntityType.FOX, 15).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.FOX, 16).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.FOX, 17).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.FOX, 18).removed(); + + registerMetaHandler().filter(EntityType1_14.EntityType.PANDA, 15).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.PANDA, 16).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.PANDA, 17).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.PANDA, 18).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.PANDA, 19).removed(); + registerMetaHandler().filter(EntityType1_14.EntityType.PANDA, 20).removed(); registerMetaHandler().handle(e -> { if (e.getData().getMetaType().getTypeID() == 6) { // Slot