Cache entity constructors for a small performance optimization

This commit is contained in:
LexManos 2017-01-17 13:07:22 -08:00
parent 926472b359
commit 50bf03b82b
6 changed files with 116 additions and 14 deletions

View file

@ -242,13 +242,13 @@
}
},
{
"name": "com.mojang:realms:1.10.8",
"name": "com.mojang:realms:1.10.10",
"downloads": {
"artifact": {
"size": 3025164,
"sha1": "67560bbd6a83d48ae8b956f1feac09010bde879c",
"path": "com/mojang/realms/1.10.8/realms-1.10.8.jar",
"url": "https://libraries.minecraft.net/com/mojang/realms/1.10.8/realms-1.10.8.jar"
"size": 3031435,
"sha1": "92d9ba93e1e99b75f2776062a5515f6aa88d9f10",
"path": "com/mojang/realms/1.10.10/realms-1.10.10.jar",
"url": "https://libraries.minecraft.net/com/mojang/realms/1.10.10/realms-1.10.10.jar"
}
}
},
@ -558,6 +558,6 @@
"minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}",
"minimumLauncherVersion": 18,
"releaseTime": "2016-12-21T09:29:12+00:00",
"time": "2016-12-21T09:42:21+00:00",
"time": "2017-01-12T10:44:50+00:00",
"type": "release"
}

View file

@ -63,16 +63,25 @@
@Nullable
public static Entity func_191304_a(@Nullable Class <? extends Entity > p_191304_0_, World p_191304_1_)
{
@@ -174,7 +186,7 @@
@@ -168,13 +180,15 @@
@SideOnly(Side.CLIENT)
public static Entity func_75616_a(int p_75616_0_, World p_75616_1_)
{
- return func_191304_a(func_90035_a(p_75616_0_), p_75616_1_);
+ net.minecraftforge.fml.common.registry.EntityEntry entry = net.minecraftforge.fml.common.registry.GameData.getEntityRegistry().func_148754_a(p_75616_0_);
+ return entry == null ? null : entry.newInstance(p_75616_1_);
}
@Nullable
public static Entity func_188429_b(ResourceLocation p_188429_0_, World p_188429_1_)
{
- return func_191304_a((Class)field_191308_b.func_82594_a(p_188429_0_), p_188429_1_);
+ return func_191304_a(getClass(p_188429_0_), p_188429_1_);
+ net.minecraftforge.fml.common.registry.EntityEntry entry = net.minecraftforge.fml.common.registry.ForgeRegistries.ENTITIES.getValue(p_188429_0_);
+ return entry == null ? null : entry.newInstance(p_188429_1_);
}
@Nullable
@@ -189,7 +201,17 @@
@@ -189,7 +203,17 @@
}
else
{
@ -90,7 +99,7 @@
}
return entity;
@@ -197,7 +219,7 @@
@@ -197,7 +221,7 @@
public static Set<ResourceLocation> func_180124_b()
{
@ -99,7 +108,7 @@
}
public static boolean func_180123_a(Entity p_180123_0_, ResourceLocation p_180123_1_)
@@ -336,7 +358,7 @@
@@ -336,7 +360,7 @@
func_191305_a("zombie_horse", 3232308, 9945732);
func_191305_a("zombie_pigman", 15373203, 5009705);
func_191305_a("zombie_villager", 5651507, 7969893);
@ -108,7 +117,7 @@
}
private static void func_191303_a(int p_191303_0_, String p_191303_1_, Class <? extends Entity > p_191303_2_, String p_191303_3_)
@@ -357,22 +379,19 @@
@@ -357,22 +381,19 @@
else
{
ResourceLocation resourcelocation = new ResourceLocation(p_191303_1_);

View file

@ -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();
@@ -136,7 +138,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)
{
@@ -146,8 +148,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;
}
@@ -258,7 +263,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)
{

View file

@ -154,3 +154,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)));
@@ -549,6 +631,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_)
{
@@ -556,12 +639,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

View file

@ -18,9 +18,15 @@
*/
package net.minecraftforge.fml.common.registry;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import com.google.common.base.Throwables;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityList.EntityEggInfo;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl;
public class EntityEntry extends Impl<EntityEntry>
@ -28,11 +34,30 @@ public class EntityEntry extends Impl<EntityEntry>
private Class<? extends Entity> cls;
private String name;
private EntityEggInfo egg;
private Constructor<?> ctr;
public EntityEntry(Class<? extends Entity> cls, String name)
{
this.cls = cls;
this.name = name;
init();
}
//Protected method, to make this optional, in case people subclass this to have a better factory.
protected void init()
{
try
{
this.ctr = this.cls.getConstructor(World.class);
}
catch (NoSuchMethodException e)
{
throw new RuntimeException("Invalid class " + this.cls + " no constructor taking " + World.class.getName());
}
catch (SecurityException e)
{
Throwables.propagate(e);
}
}
public Class<? extends Entity> getEntityClass(){ return this.cls; }
@ -45,4 +70,17 @@ public class EntityEntry extends Impl<EntityEntry>
if (this.getRegistryName() != null)
EntityList.ENTITY_EGGS.put(this.getRegistryName(), egg);
}
public Entity newInstance(World world)
{
try
{
return (Entity)this.ctr.newInstance(world);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
}

View file

@ -25,7 +25,7 @@ import java.io.IOException;
/**
* Test for {@link TextureStitchEvent.Pre}.
*/
@Mod(modid = CustomSpriteTest.MOD_ID, name = CustomSpriteTest.NAME, version = "1.0")
@Mod(modid = CustomSpriteTest.MOD_ID, name = CustomSpriteTest.NAME, version = "1.0", clientSideOnly = true)
public class CustomSpriteTest
{
static final String MOD_ID = "custom_sprite_test";