From 6c512a082d6cbdc38cf066e6b7a65309f71e56c5 Mon Sep 17 00:00:00 2001 From: MeFisto94 Date: Fri, 28 Aug 2020 01:44:21 +0200 Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and non-conflicting Entity Ids --- ...y-Counter-to-allow-plugins-to-use-va.patch | 25 +++++++++++++ ...y-Counter-to-allow-plugins-to-use-va.patch | 37 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Spigot-API-Patches/0227-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch create mode 100644 Spigot-Server-Patches/0581-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch diff --git a/Spigot-API-Patches/0227-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch b/Spigot-API-Patches/0227-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch new file mode 100644 index 0000000000..d67d1a631e --- /dev/null +++ b/Spigot-API-Patches/0227-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MeFisto94 +Date: Fri, 28 Aug 2020 01:41:31 +0200 +Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and + non-conflicting Entity Ids + + +diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java +index ac43afbf6230a481ab8cffbb3bc91b716316c00d..931ffa38faab86445a5d63364a47cb653ca3d4ed 100644 +--- a/src/main/java/org/bukkit/UnsafeValues.java ++++ b/src/main/java/org/bukkit/UnsafeValues.java +@@ -116,5 +116,13 @@ public interface UnsafeValues { + * @return the translation key + */ + String getTranslationKey(org.bukkit.entity.EntityType type); ++ ++ /** ++ * Creates and returns the next EntityId available. ++ *

++ * Use this when sending custom packets, so that there are no collisions on the client or server. ++ */ ++ public int nextEntityId(); ++ + // Paper end + } diff --git a/Spigot-Server-Patches/0581-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch b/Spigot-Server-Patches/0581-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch new file mode 100644 index 0000000000..d9fe692fbf --- /dev/null +++ b/Spigot-Server-Patches/0581-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MeFisto94 +Date: Fri, 28 Aug 2020 01:41:26 +0200 +Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and + non-conflicting Entity Ids + + +diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java +index 5e1978d1c96dede07ead967c1e85a352348e7777..ebdbbeb1b55b428dde3ab1c9691cb153c6c2fe76 100644 +--- a/src/main/java/net/minecraft/server/Entity.java ++++ b/src/main/java/net/minecraft/server/Entity.java +@@ -3374,4 +3374,10 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke + + void accept(Entity entity, double d0, double d1, double d2); + } ++ ++ // Paper start ++ public static int nextEntityId() { ++ return entityCount.incrementAndGet(); ++ } ++ // Paper end + } +diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +index 0b2bc20d1074757ab69eb6715d9b2d0d2065b2db..3ebaa9463e365831de37d8fa3cc191693f5b856f 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +@@ -410,6 +410,10 @@ public final class CraftMagicNumbers implements UnsafeValues { + return net.minecraft.server.EntityTypes.getByName(type.getName()).map(net.minecraft.server.EntityTypes::getDescriptionId).orElse(null); + } + ++ public int nextEntityId() { ++ return net.minecraft.server.Entity.nextEntityId(); ++ } ++ + // Paper end + + /**