From 88cfa4077605e2e421535ca9a0624bf0503e9408 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 22 May 2019 15:27:48 +0200 Subject: [PATCH] Fix painting and xp orb tracker --- .../api/entities/types/EntityType1_14.java | 4 +- .../packets/EntityPackets1_14.java | 43 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) 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 3ea747ea..25e531bd 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 @@ -2,7 +2,7 @@ package nl.matsv.viabackwards.api.entities.types; import lombok.AllArgsConstructor; import lombok.Getter; -import us.myles.ViaVersion.api.Via; +import nl.matsv.viabackwards.ViaBackwards; import java.util.ArrayList; import java.util.List; @@ -13,7 +13,7 @@ public class EntityType1_14 { Optional type = EntityType.findById(typeID); if (!type.isPresent()) { - Via.getPlatform().getLogger().severe("Could not find type id " + typeID); + ViaBackwards.getPlatform().getLogger().severe("Could not find type id " + typeID); return EntityType.ENTITY; // Fall back to the basic ENTITY } 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 2f4126f9..2a136819 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 @@ -18,7 +18,6 @@ import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.MetaType; 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; @@ -26,7 +25,6 @@ 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_13to1_12_2.data.Particle; -import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import java.util.Optional; @@ -68,7 +66,7 @@ public class EntityPackets1_14 extends EntityRewriter { @Override public void handle(PacketWrapper wrapper) throws Exception { int id = wrapper.get(Type.BYTE, 0); - EntityType1_13.EntityType entityType = EntityType1_13.getTypeFromId(EntityTypeMapping.getOldId(id).orElse(id), false); + 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()); @@ -128,10 +126,11 @@ public class EntityPackets1_14 extends EntityRewriter { ); Optional oldId = EntityTypeMapping.getOldId(type); if (!oldId.isPresent()) { - Optional oldType = getEntityData(entityType);if (!oldType.isPresent()) { + Optional oldType = getEntityData(entityType); + if (!oldType.isPresent()) { ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13.2 entity type for 1.14 entity type " + type + "/" + entityType); wrapper.cancel(); - }else{ + } else { wrapper.set(Type.VAR_INT, 1, oldType.get().getReplacementId()); } } else { @@ -175,6 +174,26 @@ public class EntityPackets1_14 extends EntityRewriter { } }); + // Spawn Experience Orb + protocol.registerOutgoing(State.PLAY, 0x01, 0x01, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); // 0 - Entity id + + // Track entity + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + EntityType1_14.EntityType.XP_ORB + ); + } + }); + } + }); + // Spawn painting protocol.registerOutgoing(State.PLAY, 0x04, 0x04, new PacketRemapper() { @Override @@ -184,6 +203,18 @@ public class EntityPackets1_14 extends EntityRewriter { map(Type.VAR_INT); map(Type.POSITION1_14, Type.POSITION); map(Type.BYTE); + + // Track entity + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + EntityType1_14.EntityType.PAINTING + ); + } + }); } }); @@ -430,7 +461,7 @@ public class EntityPackets1_14 extends EntityRewriter { Metadata meta = e.getData(); int typeId = meta.getMetaType().getTypeID(); if (typeId > 15) { - ViaBackwards.getPlatform().getLogger().warning("New 1.14 metadata was not handled: " + meta + " entity: " + e.getEntity().getType()); + ViaBackwards.getPlatform().getLogger().warning("New 1.14 metadata was not handled: " + meta + " entity: " + e.getEntity().getType()); return null; } return meta;