diff options
5 files changed, 65 insertions, 46 deletions
diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index 79e946c45d..c142843642 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -49,6 +49,7 @@ import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.core.util.minecraft.NBTUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.core.util.sys.SystemUtils; +import gtPlusPlus.plugin.villagers.tile.TileEntityGenericSpawner; import ic2.core.Ic2Items; import ic2.core.init.InternalName; import ic2.core.item.resources.ItemCell; @@ -828,4 +829,16 @@ public class Utils { } } + public static void createNewMobSpawner(int aID, Entity aEntity) { + Class<Entity> c; + if (aEntity instanceof Entity) { + c = (Class<Entity>) aEntity.getClass(); + TileEntityGenericSpawner.registerNewMobSpawner(aID, c); + } + } + + public static void createNewMobSpawner(int aID, Class aEntity) { + TileEntityGenericSpawner.registerNewMobSpawner(aID, aEntity); + } + } diff --git a/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java b/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java index 9c15426113..5c97623873 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java +++ b/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java @@ -7,7 +7,9 @@ import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; import gtPlusPlus.api.interfaces.IPlugin; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.entity.monster.EntityGiantChickenBase; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.plugin.manager.Core_Manager; import net.minecraft.util.ResourceLocation; @@ -33,18 +35,20 @@ public class Core_VillagerAdditions implements IPlugin { if (shouldLoad) { //Register all Villager ID's and their Custom Trades. - for (Pair<Integer, IVillageTradeHandler> g : mVillagerTrades) { - if (g != null && g.getKey() != null) { - VillagerRegistry.instance().registerVillagerId(g.getKey()); - if (g.getValue() != null) { - VillagerRegistry.instance().registerVillageTradeHandler(g.getKey(), g.getValue()); - } - if (mVillagerSkins.get(g.getKey()) != null) { - VillagerRegistry.instance().registerVillagerSkin(g.getKey(), mVillagerSkins.get(g.getKey())); + if (mVillagerTrades.size() > 0) { + for (Pair<Integer, IVillageTradeHandler> g : mVillagerTrades) { + if (g != null && g.getKey() != null) { + VillagerRegistry.instance().registerVillagerId(g.getKey()); + if (g.getValue() != null) { + VillagerRegistry.instance().registerVillageTradeHandler(g.getKey(), g.getValue()); + } + if (mVillagerSkins.get(g.getKey()) != null) { + VillagerRegistry.instance().registerVillagerSkin(g.getKey(), mVillagerSkins.get(g.getKey())); + } } } + return true; } - return true; } return false; } @@ -59,9 +63,9 @@ public class Core_VillagerAdditions implements IPlugin { @Override public boolean postInit() { if (shouldLoad) { - - - + + Utils.createNewMobSpawner(0, EntityGiantChickenBase.class); + return true; } return false; diff --git a/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java b/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java index 596db288d4..3139bbe698 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java +++ b/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java @@ -2,10 +2,8 @@ package gtPlusPlus.plugin.villagers; import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.plugin.villagers.entity.EntityBaseVillager; -import gtPlusPlus.plugin.villagers.tile.TileEntityGenericSpawner; -import net.minecraft.entity.Entity; -import net.minecraft.entity.passive.EntityVillager; import net.minecraft.util.ResourceLocation; public class VillagerUtils { @@ -13,8 +11,6 @@ public class VillagerUtils { public static void registerNewVillager(int aID, String aName, Object aProfession, Object aCareer, ResourceLocation aSkin, IVillageTradeHandler aCustomTrade) { - - //Register Custom Trade to Registry. if (aCustomTrade != null) { Core_VillagerAdditions.mVillagerTrades.put(new Pair<Integer, IVillageTradeHandler>(aID, aCustomTrade)); @@ -25,22 +21,10 @@ public class VillagerUtils { } EntityBaseVillager entityvillager = new EntityBaseVillager(null, aID); - createNewMobSpawner(aID, entityvillager); + Utils.createNewMobSpawner(aID, entityvillager); } - - - - - - - public static void createNewMobSpawner(int aID, Entity aEntity) { - TileEntityGenericSpawner.registerNewMobSpawner(aID, aEntity); - } - - - } diff --git a/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java b/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java index c7ffd6ee8c..28416793f5 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java +++ b/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java @@ -1,23 +1,35 @@ package gtPlusPlus.plugin.villagers.tile; -import net.minecraft.init.Blocks; +import cpw.mods.fml.common.registry.EntityRegistry; +import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; +import gtPlusPlus.core.block.ModBlocks; +import net.minecraft.entity.Entity; import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class MobSpawnerCustomLogic extends MobSpawnerBaseLogic { - private TileEntity mTile; + private TileEntityGenericSpawner mTile; - public MobSpawnerCustomLogic(TileEntity tile) { + public MobSpawnerCustomLogic(TileEntityGenericSpawner tile) { if (tile != null) { mTile = tile; } + + if (TileEntityGenericSpawner.mSpawners.get(mTile.getID()) != null) { + Class<Entity> c = TileEntityGenericSpawner.mSpawners.get(mTile.getID()); + EntityRegistration x = EntityRegistry.instance().lookupModSpawn(c, false); + if (x != null) { + this.setEntityName(x.getEntityName()); + } + } + } @Override public void func_98267_a(int eventID) { - if (mTile != null) mTile.getWorldObj().addBlockEvent(mTile.xCoord, mTile.yCoord, mTile.zCoord, Blocks.mob_spawner, eventID, 0); + if (mTile != null) mTile.getWorldObj().addBlockEvent(mTile.xCoord, mTile.yCoord, mTile.zCoord, ModBlocks.blockCustomMobSpawner, eventID, 0); } @Override diff --git a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java index 2dbd21dd3b..f27e1c1add 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java +++ b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java @@ -1,6 +1,5 @@ package gtPlusPlus.plugin.villagers.tile; -import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; @@ -18,14 +17,14 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { */ /** A HashMap storing string names of classes mapping to the actual java.lang.Class type. */ - private static Map nameToClassMap_Ex = new HashMap(); + private static Map<?, ?> nameToClassMap_Ex = new HashMap<Object, Object>(); /** A HashMap storing the classes and mapping to the string names (reverse of nameToClassMap). */ - private static Map classToNameMap_Ex = new HashMap(); + private static Map<?, ?> classToNameMap_Ex = new HashMap<Object, Object>(); /** * The Mob Spawner Map */ - public static HashMap<Integer, Entity> mSpawners = new HashMap<Integer, Entity>(); + public static HashMap<Integer, Class<Entity>> mSpawners = new HashMap<Integer, Class<Entity>>(); /** * Registers a New Mob Spawner Type @@ -35,7 +34,7 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { * @param aEntity * - the Entity which you'd like to spawn */ - public static boolean registerNewMobSpawner(int aID, Entity aEntity) { + public static boolean registerNewMobSpawner(int aID, Class<Entity> aEntity) { int registered = mSpawners.size(); mSpawners.put(aID, aEntity); return mSpawners.size() > registered; @@ -48,7 +47,8 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { /** * The {@link Entity} type which spawns. */ - private final Entity mSpawnType; + protected int mID; + private final Class mSpawnType; private MobSpawnerCustomLogic spawnerLogic; /* @@ -62,6 +62,7 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { * - The ID in the {@link mSpawners} map. */ public TileEntityGenericSpawner(int aID) { + mID = aID; if (mSpawners.get(aID) != null) { mSpawnType = mSpawners.get(aID); } else { @@ -81,9 +82,10 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { * - The {@link Entity} type which will be spawned. */ public TileEntityGenericSpawner(int aID, Entity aEntity) { + mID = aID; if (aEntity != null) { - mSpawnType = aEntity; - registerNewMobSpawner(aID, aEntity); + mSpawnType = aEntity.getClass(); + registerNewMobSpawner(aID, mSpawnType); } else { mSpawnType = null; } @@ -102,6 +104,10 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { private final void generateLogicObject() { spawnerLogic = new MobSpawnerCustomLogic(this); } + + public int getID() { + return this.mID; + } @Override public void readFromNBT(NBTTagCompound p_145839_1_) { @@ -110,6 +116,7 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { this.xCoord = p_145839_1_.getInteger("x"); this.yCoord = p_145839_1_.getInteger("y"); this.zCoord = p_145839_1_.getInteger("z"); + this.mID = p_145839_1_.getInteger("mID"); } } @@ -127,9 +134,8 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { p_145841_1_.setInteger("x", this.xCoord); p_145841_1_.setInteger("y", this.yCoord); p_145841_1_.setInteger("z", this.zCoord); + p_145841_1_.setInteger("mID", this.mID); } - - this.getLogic().writeToNBT(p_145841_1_); } } @@ -154,10 +160,10 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { } else { try { if (nameToClassMap_Ex == null) { - nameToClassMap_Ex = (Map) ReflectionUtils.getField(getClass(), "nameToClassMap").get(this); + nameToClassMap_Ex = (Map<?, ?>) ReflectionUtils.getField(getClass(), "nameToClassMap").get(this); } if (classToNameMap_Ex == null) { - classToNameMap_Ex = (Map) ReflectionUtils.getField(getClass(), "classToNameMap").get(this); + classToNameMap_Ex = (Map<?, ?>) ReflectionUtils.getField(getClass(), "classToNameMap").get(this); } if (nameToClassMap_Ex != null && classToNameMap_Ex != null) { isReady = true; |