From 680786840c61d8a407ebc6c0c09bccad74f0a909 Mon Sep 17 00:00:00 2001 From: copyboy Date: Wed, 4 Sep 2013 10:10:28 +0200 Subject: [PATCH] Remove lag machine EntityUtils.getIdentifier --- .../copy/betterstorage/item/ItemBackpack.java | 4 ++-- .../betterstorage/misc/PropertiesBackpack.java | 3 +-- .../copy/betterstorage/proxy/CommonProxy.java | 2 +- .../copy/betterstorage/utils/EntityUtils.java | 18 ++++++------------ 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/net/mcft/copy/betterstorage/item/ItemBackpack.java b/src/net/mcft/copy/betterstorage/item/ItemBackpack.java index 5223b656..a6331c14 100644 --- a/src/net/mcft/copy/betterstorage/item/ItemBackpack.java +++ b/src/net/mcft/copy/betterstorage/item/ItemBackpack.java @@ -245,10 +245,10 @@ public static IInventory getBackpackItems(EntityLivingBase carrier) { } public static void initBackpackData(EntityLivingBase entity) { - EntityUtils.createProperties(entity, PropertiesBackpack.class); + EntityUtils.createProperties(entity, PropertiesBackpack.class, PropertiesBackpack.identifier); } public static PropertiesBackpack getBackpackData(EntityLivingBase entity) { - PropertiesBackpack backpackData = EntityUtils.getOrCreateProperties(entity, PropertiesBackpack.class); + PropertiesBackpack backpackData = EntityUtils.getOrCreateProperties(entity, PropertiesBackpack.class, PropertiesBackpack.identifier); if (!backpackData.initialized) { ItemBackpack.initBackpackOpen(entity); updateHasItems(entity, backpackData); diff --git a/src/net/mcft/copy/betterstorage/misc/PropertiesBackpack.java b/src/net/mcft/copy/betterstorage/misc/PropertiesBackpack.java index 87d5e23d..787ec1ee 100644 --- a/src/net/mcft/copy/betterstorage/misc/PropertiesBackpack.java +++ b/src/net/mcft/copy/betterstorage/misc/PropertiesBackpack.java @@ -11,7 +11,6 @@ public class PropertiesBackpack implements IExtendedEntityProperties { public static final String identifier = Constants.modId + ".backpack"; - // public EntityLiving entity; public ItemStack[] contents = null; /** If the backpack has been initialized for the entity yet. */ @@ -30,7 +29,7 @@ public class PropertiesBackpack implements IExtendedEntityProperties { public float prevLidAngle = 0; @Override - public void init(Entity entity, World world) {} + public void init(Entity entity, World world) { } @Override public void saveNBTData(NBTTagCompound compound) { diff --git a/src/net/mcft/copy/betterstorage/proxy/CommonProxy.java b/src/net/mcft/copy/betterstorage/proxy/CommonProxy.java index 0506a404..2bf23ef8 100644 --- a/src/net/mcft/copy/betterstorage/proxy/CommonProxy.java +++ b/src/net/mcft/copy/betterstorage/proxy/CommonProxy.java @@ -233,7 +233,7 @@ public void onLivingUpdate(LivingUpdateEvent event) { PropertiesBackpack backpackData; if (backpack == null) { - backpackData = EntityUtils.getProperties(entity, PropertiesBackpack.class); + backpackData = EntityUtils.getProperties(entity, PropertiesBackpack.class, PropertiesBackpack.identifier); if (backpackData == null) return; // If the entity is supposed to spawn with diff --git a/src/net/mcft/copy/betterstorage/utils/EntityUtils.java b/src/net/mcft/copy/betterstorage/utils/EntityUtils.java index d545fd4e..27113835 100644 --- a/src/net/mcft/copy/betterstorage/utils/EntityUtils.java +++ b/src/net/mcft/copy/betterstorage/utils/EntityUtils.java @@ -7,28 +7,22 @@ public final class EntityUtils { private EntityUtils() { } - private static String getIdentifier(Class propertiesClass) { - try { return (String)propertiesClass.getField("identifier").get(null); } - catch (Exception e) { throw new RuntimeException(e); } - } - - public static T getProperties(Entity entity, Class propertiesClass) { - String identifier = getIdentifier(propertiesClass); + public static T getProperties(Entity entity, Class propertiesClass, String identifier) { IExtendedEntityProperties properties = entity.getExtendedProperties(identifier); return (propertiesClass.isInstance(properties) ? (T)properties : null); } - public static T createProperties(Entity entity, Class propertiesClass) { + public static T createProperties(Entity entity, Class propertiesClass, String identifier) { try { T properties = propertiesClass.getConstructor().newInstance(); - entity.registerExtendedProperties(getIdentifier(propertiesClass), properties); + entity.registerExtendedProperties(identifier, properties); return properties; } catch (Exception e) { throw new RuntimeException(e); } } - public static T getOrCreateProperties(Entity entity, Class propertiesClass) { - T properties = getProperties(entity, propertiesClass); - return ((properties != null) ? properties : createProperties(entity, propertiesClass)); + public static T getOrCreateProperties(Entity entity, Class propertiesClass, String identifier) { + T properties = getProperties(entity, propertiesClass, identifier); + return ((properties != null) ? properties : createProperties(entity, propertiesClass, identifier)); } }