From 08b921729dcf633fd9b0d8a5e6389d1d400b9a80 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Sun, 15 Dec 2024 10:12:05 +0100 Subject: [PATCH] Fix entity defaults across all protocols (#4312) Minecraft <= 1.13.2 silently ignores unknown entity type ids and doesn't print any warning, while we currently still track them. Minecraft 1.14+ will spawn a pig if the entity type is invalid while we track ENTITY as wrong type. Both cases can cause various entity data issues where the server sends wrong data for non-existing entities while we still handle it. --- .../minecraft/entities/EntityTypes1_10.java | 5 -- .../minecraft/entities/EntityTypes1_11.java | 5 -- .../minecraft/entities/EntityTypes1_12.java | 5 -- .../minecraft/entities/EntityTypes1_13.java | 5 -- .../minecraft/entities/EntityTypes1_14.java | 4 +- .../minecraft/entities/EntityTypes1_15.java | 4 +- .../minecraft/entities/EntityTypes1_16.java | 4 +- .../minecraft/entities/EntityTypes1_16_2.java | 4 +- .../minecraft/entities/EntityTypes1_17.java | 4 +- .../minecraft/entities/EntityTypes1_19.java | 4 +- .../minecraft/entities/EntityTypes1_19_3.java | 4 +- .../minecraft/entities/EntityTypes1_19_4.java | 4 +- .../minecraft/entities/EntityTypes1_20_3.java | 4 +- .../minecraft/entities/EntityTypes1_20_5.java | 4 +- .../minecraft/entities/EntityTypes1_21_2.java | 2 +- .../minecraft/entities/EntityTypes1_21_4.java | 2 +- .../minecraft/entities/EntityTypes1_8.java | 5 -- .../minecraft/entities/EntityTypes1_9.java | 5 -- .../rewriter/EntityPacketRewriter1_11.java | 1 - .../rewriter/EntityPacketRewriter1_14.java | 74 ++++++++++--------- .../rewriter/SpawnPacketRewriter1_9.java | 17 ++++- .../viaversion/rewriter/EntityRewriter.java | 6 ++ 22 files changed, 82 insertions(+), 90 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java index 432324c26..f0db21324 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_10.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.api.minecraft.entities; -import com.viaversion.viaversion.api.Via; import java.util.HashMap; import java.util.Map; @@ -36,10 +35,6 @@ public class EntityTypes1_10 { } else { type = EntityType.findById(typeId); } - if (type == null) { - Via.getPlatform().getLogger().severe("Could not find 1.10 type id " + typeId + " objectType=" + object); - return EntityType.ENTITY; // Fall back to the basic ENTITY - } return type; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java index e3a7b35cb..ec62b8c7a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_11.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.api.minecraft.entities; -import com.viaversion.viaversion.api.Via; import java.util.HashMap; import java.util.Map; @@ -36,10 +35,6 @@ public class EntityTypes1_11 { } else { type = EntityType.findById(typeId); } - if (type == null) { - Via.getPlatform().getLogger().severe("Could not find 1.11 type id " + typeId + " objectType=" + object); - return EntityType.ENTITY; // Fall back to the basic ENTITY - } return type; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java index 6a2b140bb..be303798c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_12.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.api.minecraft.entities; -import com.viaversion.viaversion.api.Via; import java.util.HashMap; import java.util.Map; @@ -36,10 +35,6 @@ public class EntityTypes1_12 { } else { type = EntityType.findById(typeId); } - if (type == null) { - Via.getPlatform().getLogger().severe("Could not find 1.12 type id " + typeId + " objectType=" + object); - return EntityType.ENTITY; // Fall back to the basic ENTITY - } return type; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java index c7e54a696..7beb8a133 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_13.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.api.minecraft.entities; -import com.viaversion.viaversion.api.Via; import java.util.HashMap; import java.util.Map; @@ -36,10 +35,6 @@ public class EntityTypes1_13 { } else { type = EntityType.findById(typeId); } - if (type == null) { - Via.getPlatform().getLogger().severe("Could not find 1.13 type id " + typeId + " objectType=" + object); - return EntityType.ENTITY; // Fall back to the basic ENTITY - } return type; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_14.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_14.java index 3da89730a..18610ab0d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_14.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_14 implements EntityType { @@ -246,7 +246,7 @@ public enum EntityTypes1_14 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_15.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_15.java index 0f8759b75..1aa2e9ccf 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_15.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_15.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_15 implements EntityType { @@ -247,7 +247,7 @@ public enum EntityTypes1_15 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16.java index cb687b35d..5c072a34f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_16 implements EntityType { @@ -251,7 +251,7 @@ public enum EntityTypes1_16 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16_2.java index e04fb130b..2df0306ea 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_16_2.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_16_2 implements EntityType { @@ -254,7 +254,7 @@ public enum EntityTypes1_16_2 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_17.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_17.java index 30bcd505d..25425ec37 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_17.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_17.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_17 implements EntityType { @@ -260,7 +260,7 @@ public enum EntityTypes1_17 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19.java index ab03cad9d..ba97756e7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_19 implements EntityType { @@ -265,7 +265,7 @@ public enum EntityTypes1_19 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_3.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_3.java index 07aaa7070..2f404a8cc 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_3.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_3.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_19_3 implements EntityType { @@ -266,7 +266,7 @@ public enum EntityTypes1_19_3 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_4.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_4.java index 6385b87f1..df1625845 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_4.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_19_4.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_19_4 implements EntityType { @@ -273,7 +273,7 @@ public enum EntityTypes1_19_4 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_3.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_3.java index df411972f..56e976a24 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_3.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_3.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_20_3 implements EntityType { @@ -275,7 +275,7 @@ public enum EntityTypes1_20_3 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_5.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_5.java index 5a1cc711e..636f00628 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_5.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_20_5.java @@ -25,8 +25,8 @@ package com.viaversion.viaversion.api.minecraft.entities; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.util.EntityTypeUtil; -import java.util.Locale; import com.viaversion.viaversion.util.Key; +import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; public enum EntityTypes1_20_5 implements EntityType { @@ -281,7 +281,7 @@ public enum EntityTypes1_20_5 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_2.java index 05a635439..36a967f9f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_2.java @@ -305,7 +305,7 @@ public enum EntityTypes1_21_2 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_4.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_4.java index c66581468..cd8330f13 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_4.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_21_4.java @@ -304,7 +304,7 @@ public enum EntityTypes1_21_4 implements EntityType { } public static EntityType getTypeFromId(final int typeId) { - return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY); + return EntityTypeUtil.getTypeFromId(TYPES, typeId, PIG); } public static void initialize(final Protocol protocol) { diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_8.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_8.java index 3a8f1bb81..14d71e2c5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_8.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_8.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.api.minecraft.entities; -import com.viaversion.viaversion.api.Via; import java.util.HashMap; import java.util.Map; @@ -36,10 +35,6 @@ public class EntityTypes1_8 { } else { type = EntityType.findById(typeId); } - if (type == null) { - Via.getPlatform().getLogger().severe("Could not find 1.8 type id " + typeId + " objectType=" + object); - return EntityType.ENTITY; // Fall back to the basic ENTITY - } return type; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_9.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_9.java index f32f53e43..7baee483e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_9.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/entities/EntityTypes1_9.java @@ -22,7 +22,6 @@ */ package com.viaversion.viaversion.api.minecraft.entities; -import com.viaversion.viaversion.api.Via; import java.util.HashMap; import java.util.Map; @@ -36,10 +35,6 @@ public class EntityTypes1_9 { } else { type = EntityType.findById(typeId); } - if (type == null) { - Via.getPlatform().getLogger().severe("Could not find 1.9 type id " + typeId + " objectType=" + object); - return EntityType.ENTITY; // Fall back to the basic ENTITY - } return type; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java index 9e7e8b0c9..8ae713e17 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_10to1_11/rewriter/EntityPacketRewriter1_11.java @@ -331,7 +331,6 @@ public class EntityPacketRewriter1_11 extends EntityRewriter entityData) { EntityType type = EntityType.findById(numType); if (type == null) { - Via.getManager().getPlatform().getLogger().severe("Error: could not find Entity type " + numType + " with entity data: " + entityData); return null; } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java index 8d41df011..aa2398b96 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_13_2to1_14/rewriter/EntityPacketRewriter1_14.java @@ -18,15 +18,15 @@ package com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.BlockPosition; +import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.VillagerData; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; +import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; @@ -82,41 +82,42 @@ public class EntityPacketRewriter1_14 extends EntityRewriter EntityTypes1_14.CHEST_MINECART.getId(); - case 2 -> EntityTypes1_14.FURNACE_MINECART.getId(); - case 3 -> EntityTypes1_14.TNT_MINECART.getId(); - case 4 -> EntityTypes1_14.SPAWNER_MINECART.getId(); - case 5 -> EntityTypes1_14.HOPPER_MINECART.getId(); - case 6 -> EntityTypes1_14.COMMAND_BLOCK_MINECART.getId(); - default -> typeId; // default 0 = rideable minecart - }; - } else if ((type1_14.is(EntityTypes1_14.ITEM) && data > 0) - || type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { - if (type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { - wrapper.set(Types.INT, 0, data - 1); - } - // send velocity in separate packet, 1.14 is now ignoring the velocity - PacketWrapper velocity = wrapper.create(ClientboundPackets1_14.SET_ENTITY_MOTION); - velocity.write(Types.VAR_INT, entityId); - velocity.write(Types.SHORT, wrapper.get(Types.SHORT, 0)); - velocity.write(Types.SHORT, wrapper.get(Types.SHORT, 1)); - velocity.write(Types.SHORT, wrapper.get(Types.SHORT, 2)); - velocity.scheduleSend(Protocol1_13_2To1_14.class); + int data = wrapper.get(Types.INT, 0); + if (type1_14.is(EntityTypes1_14.FALLING_BLOCK)) { + wrapper.set(Types.INT, 0, protocol.getMappingData().getNewBlockStateId(data)); + } else if (type1_14.is(EntityTypes1_14.MINECART)) { + typeId = switch (data) { + case 1 -> EntityTypes1_14.CHEST_MINECART.getId(); + case 2 -> EntityTypes1_14.FURNACE_MINECART.getId(); + case 3 -> EntityTypes1_14.TNT_MINECART.getId(); + case 4 -> EntityTypes1_14.SPAWNER_MINECART.getId(); + case 5 -> EntityTypes1_14.HOPPER_MINECART.getId(); + case 6 -> EntityTypes1_14.COMMAND_BLOCK_MINECART.getId(); + default -> typeId; // default 0 = rideable minecart + }; + } else if ((type1_14.is(EntityTypes1_14.ITEM) && data > 0) + || type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { + if (type1_14.isOrHasParent(EntityTypes1_14.ABSTRACT_ARROW)) { + wrapper.set(Types.INT, 0, data - 1); } - - // Register Type ID - wrapper.user().getEntityTracker(Protocol1_13_2To1_14.class).addEntity(entityId, type1_14); + // send velocity in separate packet, 1.14 is now ignoring the velocity + PacketWrapper velocity = wrapper.create(ClientboundPackets1_14.SET_ENTITY_MOTION); + velocity.write(Types.VAR_INT, entityId); + velocity.write(Types.SHORT, wrapper.get(Types.SHORT, 0)); + velocity.write(Types.SHORT, wrapper.get(Types.SHORT, 1)); + velocity.write(Types.SHORT, wrapper.get(Types.SHORT, 2)); + velocity.scheduleSend(Protocol1_13_2To1_14.class); } + // Register Type ID + wrapper.user().getEntityTracker(Protocol1_13_2To1_14.class).addEntity(entityId, type1_14); + wrapper.set(Types.VAR_INT, 1, typeId); }); } @@ -139,7 +140,14 @@ public class EntityPacketRewriter1_14 extends EntityRewriter { + int entityType = wrapper.get(Types.VAR_INT, 1); + if (EntityTypes1_13.getTypeFromId(entityType, false) == null) { + // <= 1.13.2 will ignore unknown entity types, 1.14+ will spawn a pig as default + wrapper.cancel(); + } + trackerAndRewriterHandler(Types1_14.ENTITY_DATA_LIST).handle(wrapper); + }); } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/SpawnPacketRewriter1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/SpawnPacketRewriter1_9.java index 36734905b..dddea0519 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/SpawnPacketRewriter1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_8to1_9/rewriter/SpawnPacketRewriter1_9.java @@ -18,12 +18,13 @@ package com.viaversion.viaversion.protocols.v1_8to1_9.rewriter; import com.viaversion.viaversion.api.data.entity.EntityTracker; +import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_9; -import com.viaversion.viaversion.api.minecraft.item.DataItem; -import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_9; +import com.viaversion.viaversion.api.minecraft.item.DataItem; +import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; @@ -63,7 +64,11 @@ public class SpawnPacketRewriter1_9 { int entityID = wrapper.get(Types.VAR_INT, 0); int typeID = wrapper.get(Types.BYTE, 0); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); - tracker.addEntity(entityID, EntityTypes1_9.getTypeFromId(typeID, true)); + + EntityType entityType = EntityTypes1_9.getTypeFromId(typeID, true); + if (entityType != null) { + tracker.addEntity(entityID, entityType); + } }); map(Types.INT, toNewDouble); // 3 - X - Needs to be divided by 32 @@ -176,7 +181,11 @@ public class SpawnPacketRewriter1_9 { int entityID = wrapper.get(Types.VAR_INT, 0); int typeID = wrapper.get(Types.UNSIGNED_BYTE, 0); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_8To1_9.class); - tracker.addEntity(entityID, EntityTypes1_9.getTypeFromId(typeID, false)); + + EntityType entityType = EntityTypes1_9.getTypeFromId(typeID, false); + if (entityType != null) { + tracker.addEntity(entityID, entityType); + } }); map(Types.INT, toNewDouble); // 3 - X - Needs to be divided by 32 diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 7efdf89a7..9d9635ce7 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -510,6 +510,9 @@ public abstract class EntityRewriter