From 0813f0a914ef8bfb15c073b39b07d36c7f9b28e7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 30 Nov 2014 15:41:57 +1300 Subject: [PATCH] Instead of having a internal entityId. Use mojang's entityid's but add one everytime you want it. Also allow fetching of the next entityid to be used --- .../mineplex/core/common/util/UtilEnt.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index eca5842fd..31310033c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -33,7 +33,6 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; public class UtilEnt { - private static int entityIdCount = 455000; //Custom Entity Names private static HashMap _nameMap = new HashMap(); @@ -574,6 +573,30 @@ public class UtilEnt public static int getNewEntityId() { - return entityIdCount++; + return getNewEntityId(true); } + + /** + * Use false if you don't want to modify the next entityid to be used. + * + * Normally you want true if you want a unique entityid to use. + **/ + public static int getNewEntityId(boolean modifynumber) + { + try + { + Field field = net.minecraft.server.v1_7_R4.Entity.class.getDeclaredField("entityCount"); + field.setAccessible(true); + int entityId = field.getInt(null); + if (modifynumber) { + field.set(null, entityId+1); + } + return entityId; + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return -1; + } }