diff options
Diffstat (limited to 'src')
6 files changed, 99 insertions, 43 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/Logger.java b/src/Java/gtPlusPlus/api/objects/Logger.java index 52c1c16f52..1ecdaa9e86 100644 --- a/src/Java/gtPlusPlus/api/objects/Logger.java +++ b/src/Java/gtPlusPlus/api/objects/Logger.java @@ -127,8 +127,8 @@ public class Logger { * Special Logger for Reflection related content */ public static void REFLECTION(final String s) { - //if (CORE.DEVENV || CORE.DEBUG) - //modLogger.info("[Reflection] "+s); + if (CORE.DEVENV || CORE.DEBUG) + modLogger.info("[Reflection] "+s); } diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index c1ca513f01..be98bdf3f4 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -95,9 +95,7 @@ public final class ModBlocks { blockWitherGuard = new BlockWitherProof(); blockXpConverter = new BlockTankXpConverter(); blockCompressedObsidian = new BlockCompressedObsidian(); - blockNet = new BlockNet(); - - blockCustomMobSpawner = new BlockGenericSpawner(); + blockNet = new BlockNet(); blockFakeMiningPipe = new Mining_Pipe_Fake(); blockFakeMiningHead = new Mining_Head_Fake(); diff --git a/src/Java/gtPlusPlus/core/util/Utils.java b/src/Java/gtPlusPlus/core/util/Utils.java index c142843642..7f9aa7098b 100644 --- a/src/Java/gtPlusPlus/core/util/Utils.java +++ b/src/Java/gtPlusPlus/core/util/Utils.java @@ -15,7 +15,8 @@ import javax.xml.bind.DatatypeConverter; import org.apache.commons.lang3.EnumUtils; import cpw.mods.fml.common.FMLCommonHandler; - +import cpw.mods.fml.common.registry.EntityRegistry; +import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; @@ -833,12 +834,21 @@ public class Utils { Class<Entity> c; if (aEntity instanceof Entity) { c = (Class<Entity>) aEntity.getClass(); - TileEntityGenericSpawner.registerNewMobSpawner(aID, c); + createNewMobSpawner(aID, c); } } - public static void createNewMobSpawner(int aID, Class aEntity) { - TileEntityGenericSpawner.registerNewMobSpawner(aID, aEntity); + public static void createNewMobSpawner(int aID, Class aEntity) { + Logger.INFO("[Spawn] Generating new spawner for entity with class ("+aEntity.getCanonicalName()+")."); + if (TileEntityGenericSpawner.registerNewMobSpawner(aID, aEntity)) { + EntityRegistration x = EntityRegistry.instance().lookupModSpawn(aEntity, false); + if (x != null) { + Logger.INFO("[Spawn] Registration for "+x.getEntityName()+" successful"); + } + } + else { + Logger.INFO("[Spawn] Registration for "+aEntity.getName()+" failed"); + } } } diff --git a/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java b/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java index 5c97623873..ee0673ee20 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java +++ b/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java @@ -7,15 +7,19 @@ 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.block.ModBlocks; import gtPlusPlus.core.entity.monster.EntityGiantChickenBase; +import gtPlusPlus.core.entity.monster.EntitySickBlaze; +import gtPlusPlus.core.entity.monster.EntityStaballoyConstruct; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; import gtPlusPlus.plugin.manager.Core_Manager; +import gtPlusPlus.plugin.villagers.block.BlockGenericSpawner; import net.minecraft.util.ResourceLocation; public class Core_VillagerAdditions implements IPlugin { - final static Core_VillagerAdditions mInstance; + public final static Core_VillagerAdditions mInstance; private static boolean shouldLoad = false; public static final HashMap<Integer, ResourceLocation> mVillagerSkins = new HashMap<Integer, ResourceLocation>(); @@ -32,8 +36,12 @@ public class Core_VillagerAdditions implements IPlugin { if (/*CORE.ConfigSwitches.enableSulfuricAcidFix || */CORE.DEVENV) { shouldLoad = true; } - if (shouldLoad) { - + if (shouldLoad) { + //Try register some test spawners + Utils.createNewMobSpawner(0, EntityGiantChickenBase.class); + Utils.createNewMobSpawner(1, EntitySickBlaze.class); + Utils.createNewMobSpawner(2, EntityStaballoyConstruct.class); + //Register all Villager ID's and their Custom Trades. if (mVillagerTrades.size() > 0) { for (Pair<Integer, IVillageTradeHandler> g : mVillagerTrades) { @@ -55,17 +63,16 @@ public class Core_VillagerAdditions implements IPlugin { @Override public boolean init() { - if (shouldLoad) + if (shouldLoad) { + ModBlocks.blockCustomMobSpawner = new BlockGenericSpawner(); return true; + } return false; } @Override public boolean postInit() { if (shouldLoad) { - - Utils.createNewMobSpawner(0, EntityGiantChickenBase.class); - return true; } return false; diff --git a/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java b/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java index ef41ddbaf0..5f3e704818 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java +++ b/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java @@ -4,8 +4,12 @@ import static gtPlusPlus.core.lib.CORE.RANDOM; import java.util.List; +import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.itemblock.ItemBlockMeta; +import gtPlusPlus.plugin.villagers.Core_VillagerAdditions; import gtPlusPlus.plugin.villagers.tile.TileEntityGenericSpawner; import net.minecraft.block.BlockMobSpawner; import net.minecraft.creativetab.CreativeTabs; @@ -21,8 +25,11 @@ public class BlockGenericSpawner extends BlockMobSpawner { this.disableStats(); this.setHardness(5.0F); this.setStepSound(soundTypeMetal); - this.setBlockName("mobSpawner"); + this.setBlockName("blockMobSpawnerEx"); this.setBlockTextureName("mob_spawner"); + this.setResistance(2000.0F); + GameRegistry.registerBlock(this, ItemBlockMeta.class, "blockMobSpawnerEx"); + Core_VillagerAdditions.mInstance.log("Registered Custom Spawner Block."); } /** @@ -45,7 +52,7 @@ public class BlockGenericSpawner extends BlockMobSpawner { @SideOnly(Side.CLIENT) public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_) { - for (int i = 0; i < TileEntityGenericSpawner.mSpawners.size(); ++i) + for (int i = 0; i < Math.max(1,TileEntityGenericSpawner.mSpawners.size()); ++i) { p_149666_3_.add(new ItemStack(p_149666_1_, 1, i)); } diff --git a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java index f27e1c1add..9f2e992d74 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java +++ b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java @@ -3,6 +3,8 @@ package gtPlusPlus.plugin.villagers.tile; import java.util.HashMap; import java.util.Map; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; @@ -36,6 +38,7 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { */ public static boolean registerNewMobSpawner(int aID, Class<Entity> aEntity) { int registered = mSpawners.size(); + Logger.INFO("Currently "+registered+" spawners are registered."); mSpawners.put(aID, aEntity); return mSpawners.size() > registered; } @@ -85,7 +88,9 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { mID = aID; if (aEntity != null) { mSpawnType = aEntity.getClass(); - registerNewMobSpawner(aID, mSpawnType); + if (mSpawners.containsKey(aID)) { + registerNewMobSpawner(aID, mSpawnType); + } } else { mSpawnType = null; } @@ -104,7 +109,7 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { private final void generateLogicObject() { spawnerLogic = new MobSpawnerCustomLogic(this); } - + public int getID() { return this.mID; } @@ -123,13 +128,19 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { @Override public void writeToNBT(NBTTagCompound p_145841_1_) { if (hasInternalFieldBeenSet()) { - - String s = (String) classToNameMap_Ex.get(TileEntity.class); - + String s = (String) classToNameMap_Ex.get(mSpawners.get(this.mID)); if (s == null){ - throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!"); + //throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!"); + s = mSpawners.containsKey(this.mID) ? mSpawners.get(this.mID).getSimpleName() : "bad.class.name"; + p_145841_1_.setString("id", s); + Logger.WARNING(this.getClass() + " is missing a mapping! This is a bug! Used key: "+s); + 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); } else { + Logger.WARNING(this.getClass() + " is not missing a mapping! Used key: "+s); p_145841_1_.setString("id", s); p_145841_1_.setInteger("x", this.xCoord); p_145841_1_.setInteger("y", this.yCoord); @@ -142,12 +153,11 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { @Override public void updateEntity() { - - - - - if (hasInternalFieldBeenSet()) { - this.getLogic().updateSpawner(); + if (Utils.isServer()) { + mTicks++; + if (hasInternalFieldBeenSet()) { + this.getLogic().updateSpawner(); + } } } @@ -158,18 +168,41 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { if (isReady && mTicks % 200 != 0) { return true; } else { - try { - if (nameToClassMap_Ex == null) { - nameToClassMap_Ex = (Map<?, ?>) ReflectionUtils.getField(getClass(), "nameToClassMap").get(this); - } - if (classToNameMap_Ex == null) { - classToNameMap_Ex = (Map<?, ?>) ReflectionUtils.getField(getClass(), "classToNameMap").get(this); - } - if (nameToClassMap_Ex != null && classToNameMap_Ex != null) { - isReady = true; - return true; - } - /*Field mInternalLogicField = ReflectionUtils.getField(getClass(), "field_145882_a"); + + if (Utils.isServer()) { + try { + Map<?, ?> a1 = (Map<?, ?>) ReflectionUtils.getField(TileEntity.class, "nameToClassMap").get(this); + Map<?, ?> a2 = (Map<?, ?>) ReflectionUtils.getField(TileEntity.class, "classToNameMap").get(this); + if (a1 != null) { + if (nameToClassMap_Ex == null) { + nameToClassMap_Ex = a1; + } + if (nameToClassMap_Ex != null) { + if (nameToClassMap_Ex.size() != a1.size()) { + nameToClassMap_Ex = a1; + } + } + } + if (a2 != null) { + if (classToNameMap_Ex == null) { + classToNameMap_Ex = a2; + } + if (classToNameMap_Ex != null) { + if (classToNameMap_Ex.size() != a2.size()) { + classToNameMap_Ex = a2; + } + } + if (nameToClassMap_Ex != null && classToNameMap_Ex != null) { + //Logger.INFO("nameToClassMap_Ex has a size of "+nameToClassMap_Ex.size()+"."); + //Logger.INFO("a1 has a size of "+a1.size()+"."); + //Logger.INFO("classToNameMap_Ex has a size of "+classToNameMap_Ex.size()+"."); + //Logger.INFO("a2 has a size of "+a2.size()+"."); + isReady = true; + return true; + } + } + + /*Field mInternalLogicField = ReflectionUtils.getField(getClass(), "field_145882_a"); if (mInternalLogicField != null) { MobSpawnerBaseLogic a = (MobSpawnerBaseLogic) mInternalLogicField.get(this); if (a != null) { @@ -180,7 +213,8 @@ public class TileEntityGenericSpawner extends TileEntityMobSpawner { } } }*/ - } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } } return false; } |