mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Cache entity constructors for a small performance optimization
(cherry picked from commit 50bf03b82b)
This commit is contained in:
1 parent
6f361dafa8
commit
b2964a1ae7
3 files changed
+93
-10
No files matched your search
@@ -1,6 +1,10 @@
|
||||
--- ../src-base/minecraft/net/minecraft/entity/EntityList.java
|
||||
+++ ../src-work/minecraft/net/minecraft/entity/EntityList.java
|
||||
@@ -93,6 +93,7 @@
|
||||
@@ -90,9 +90,11 @@
|
||||
private static final Map < Class <? extends Entity > , Integer > field_75624_e = Maps. < Class <? extends Entity > , Integer > newHashMap();
|
||||
private static final Map<String, Integer> field_180126_g = Maps.<String, Integer>newHashMap();
|
||||
public static final Map<String, EntityList.EntityEggInfo> field_75627_a = Maps.<String, EntityList.EntityEggInfo>newLinkedHashMap();
|
||||
+ private static final Map<String, java.lang.reflect.Constructor<? extends Entity>> CACHED_CONSTRUCTORS = Maps.newHashMap();
|
||||
|
||||
public static void func_75618_a(Class <? extends Entity > p_75618_0_, String p_75618_1_, int p_75618_2_)
|
||||
{
|
||||
@@ -8,19 +12,43 @@
|
||||
if (field_75625_b.containsKey(p_75618_1_))
|
||||
{
|
||||
throw new IllegalArgumentException("ID is already registered: " + p_75618_1_);
|
||||
@@ -152,9 +153,10 @@
|
||||
{
|
||||
Entity entity = null;
|
||||
@@ -132,12 +134,20 @@
|
||||
|
||||
+ Class <? extends Entity > oclass = null;
|
||||
try
|
||||
{
|
||||
- Class <? extends Entity > oclass = (Class)field_75625_b.get(p_75615_0_.func_74779_i("id"));
|
||||
+ oclass = field_75625_b.get(p_75615_0_.func_74779_i("id"));
|
||||
+ java.lang.reflect.Constructor<? extends Entity> ctr = CACHED_CONSTRUCTORS.get(p_75620_0_);
|
||||
+ if (ctr == null)
|
||||
+ {
|
||||
Class <? extends Entity > oclass = (Class)field_75625_b.get(p_75620_0_);
|
||||
|
||||
if (oclass != null)
|
||||
{
|
||||
@@ -168,7 +170,17 @@
|
||||
- entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {p_75620_1_});
|
||||
+ ctr = oclass.getConstructor(World.class);
|
||||
+ CACHED_CONSTRUCTORS.put(p_75620_0_, ctr);
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ if (ctr != null)
|
||||
+ entity = ctr.newInstance(p_75620_1_);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -154,12 +164,7 @@
|
||||
|
||||
try
|
||||
{
|
||||
- Class <? extends Entity > oclass = (Class)field_75625_b.get(p_75615_0_.func_74779_i("id"));
|
||||
-
|
||||
- if (oclass != null)
|
||||
- {
|
||||
- entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {p_75615_1_});
|
||||
- }
|
||||
+ entity = func_75620_a(p_75615_0_.func_74779_i("id"), p_75615_1_);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -168,7 +173,17 @@
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
@@ -32,13 +60,13 @@
|
||||
+ {
|
||||
+ net.minecraftforge.fml.common.FMLLog.log(org.apache.logging.log4j.Level.ERROR, e,
|
||||
+ "An Entity %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author",
|
||||
+ p_75615_0_.func_74779_i("id"), oclass.getName());
|
||||
+ p_75615_0_.func_74779_i("id"), field_75625_b.get(p_75615_0_.func_74779_i("id")).getName());
|
||||
+ entity = null;
|
||||
+ }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -208,7 +220,8 @@
|
||||
@@ -208,7 +223,8 @@
|
||||
@Nullable
|
||||
public static Entity func_188429_b(String p_188429_0_, World p_188429_1_)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,15 @@
|
||||
{
|
||||
BlockPos blockpos = func_180621_a(p_77192_1_, chunkpos1.field_77276_a, chunkpos1.field_77275_b);
|
||||
int k1 = blockpos.func_177958_n();
|
||||
@@ -135,7 +137,7 @@
|
||||
|
||||
try
|
||||
{
|
||||
- entityliving = (EntityLiving)biome$spawnlistentry.field_76300_b.getConstructor(new Class[] {World.class}).newInstance(new Object[] {p_77192_1_});
|
||||
+ entityliving = (EntityLiving)biome$spawnlistentry.newInstance(p_77192_1_);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -145,8 +147,10 @@
|
||||
|
||||
entityliving.func_70012_b((double)f, (double)i3, (double)f1, p_77192_1_.field_73012_v.nextFloat() * 360.0F, 0.0F);
|
||||
@@ -52,3 +61,12 @@
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -257,7 +262,7 @@
|
||||
|
||||
try
|
||||
{
|
||||
- entityliving = (EntityLiving)biome$spawnlistentry.field_76300_b.getConstructor(new Class[] {World.class}).newInstance(new Object[] {p_77191_0_});
|
||||
+ entityliving = (EntityLiving)biome$spawnlistentry.newInstance(p_77191_0_);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -134,3 +134,40 @@
|
||||
public static void func_185358_q()
|
||||
{
|
||||
func_185354_a(0, "ocean", new BiomeOcean((new Biome.BiomeProperties("Ocean")).func_185398_c(-1.0F).func_185400_d(0.1F)));
|
||||
@@ -547,6 +625,7 @@
|
||||
public Class <? extends EntityLiving > field_76300_b;
|
||||
public int field_76301_c;
|
||||
public int field_76299_d;
|
||||
+ private final java.lang.reflect.Constructor<?> ctr;
|
||||
|
||||
public SpawnListEntry(Class <? extends EntityLiving > p_i1970_1_, int p_i1970_2_, int p_i1970_3_, int p_i1970_4_)
|
||||
{
|
||||
@@ -554,12 +633,28 @@
|
||||
this.field_76300_b = p_i1970_1_;
|
||||
this.field_76301_c = p_i1970_3_;
|
||||
this.field_76299_d = p_i1970_4_;
|
||||
+
|
||||
+ java.lang.reflect.Constructor<?> tmp = null;
|
||||
+ try
|
||||
+ {
|
||||
+ tmp = p_i1970_1_.getConstructor(World.class);
|
||||
+ }
|
||||
+ catch (NoSuchMethodException e)
|
||||
+ {
|
||||
+ com.google.common.base.Throwables.propagate(e);
|
||||
+ }
|
||||
+ ctr = tmp;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return this.field_76300_b.getSimpleName() + "*(" + this.field_76301_c + "-" + this.field_76299_d + "):" + this.field_76292_a;
|
||||
}
|
||||
+
|
||||
+ public EntityLiving newInstance(World world) throws Exception
|
||||
+ {
|
||||
+ return (EntityLiving)ctr.newInstance(world);
|
||||
+ }
|
||||
}
|
||||
|
||||
public static enum TempCategory
|
||||
Reference in new issue
Block a user