diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-06-29 23:36:55 +1000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-06-29 23:36:55 +1000 |
commit | 97fb7abbf7954ed47eacbcfd38df03545cc0ec37 (patch) | |
tree | 0a5337042fd7d0c2ccf2cf9435896340af956ad0 | |
parent | ebac3516aada8378ca10b78acf0f942440934e6c (diff) | |
download | GT5-Unofficial-97fb7abbf7954ed47eacbcfd38df03545cc0ec37.tar.gz GT5-Unofficial-97fb7abbf7954ed47eacbcfd38df03545cc0ec37.tar.bz2 GT5-Unofficial-97fb7abbf7954ed47eacbcfd38df03545cc0ec37.zip |
% More work.
8 files changed, 242 insertions, 48 deletions
diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index 09bf3eb4af..c1ca513f01 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -16,6 +16,7 @@ import gtPlusPlus.core.block.machine.bedrock.Mining_Pipe_Fake; import gtPlusPlus.core.fluids.FluidRegistryHandler; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; +import gtPlusPlus.plugin.villagers.block.BlockGenericSpawner; import net.minecraftforge.fluids.Fluid; public final class ModBlocks { @@ -60,6 +61,8 @@ public final class ModBlocks { public static Block blockXpConverter; public static Block blockCompressedObsidian; public static Block blockNet; + + public static Block blockCustomMobSpawner; public static void init() { Logger.INFO("Initializing Blocks."); @@ -93,6 +96,8 @@ public final class ModBlocks { blockXpConverter = new BlockTankXpConverter(); blockCompressedObsidian = new BlockCompressedObsidian(); blockNet = new BlockNet(); + + blockCustomMobSpawner = new BlockGenericSpawner(); blockFakeMiningPipe = new Mining_Pipe_Fake(); blockFakeMiningHead = new Mining_Head_Fake(); diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index ae33c8428d..af384565a9 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -66,12 +66,11 @@ public class ReflectionUtils { public static boolean setField(final Object object, final String fieldName, final Object fieldValue) { Class<?> clazz = object.getClass(); - if (clazz != null) { + while (clazz != null) { try { final Field field = getField(clazz, fieldName); if (field != null) { - makeAccessible(field); - field.set(object, fieldValue); + setValue(object, field, fieldValue); return true; } } catch (final NoSuchFieldException e) { diff --git a/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java b/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java index fa3e8ccbd8..9c15426113 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java +++ b/src/Java/gtPlusPlus/plugin/villagers/Core_VillagerAdditions.java @@ -58,7 +58,10 @@ public class Core_VillagerAdditions implements IPlugin { @Override public boolean postInit() { - if (shouldLoad) { + if (shouldLoad) { + + + return true; } return false; diff --git a/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java b/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java index eb3200c21d..596db288d4 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java +++ b/src/Java/gtPlusPlus/plugin/villagers/VillagerUtils.java @@ -2,6 +2,10 @@ package gtPlusPlus.plugin.villagers; import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler; import gtPlusPlus.api.objects.data.Pair; +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 { @@ -9,6 +13,8 @@ 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)); @@ -18,7 +24,23 @@ public class VillagerUtils { Core_VillagerAdditions.mVillagerSkins.put(aID, aSkin); } + EntityBaseVillager entityvillager = new EntityBaseVillager(null, aID); + createNewMobSpawner(aID, entityvillager); + + } + + + + + + + + + + public static void createNewMobSpawner(int aID, Entity aEntity) { + TileEntityGenericSpawner.registerNewMobSpawner(aID, aEntity); } + } diff --git a/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java b/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java index 81e2d99999..ef41ddbaf0 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java +++ b/src/Java/gtPlusPlus/plugin/villagers/block/BlockGenericSpawner.java @@ -1,22 +1,54 @@ package gtPlusPlus.plugin.villagers.block; +import static gtPlusPlus.core.lib.CORE.RANDOM; + +import java.util.List; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.plugin.villagers.tile.TileEntityGenericSpawner; import net.minecraft.block.BlockMobSpawner; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockGenericSpawner extends BlockMobSpawner { - public BlockGenericSpawner () { - + public BlockGenericSpawner() { + this.disableStats(); + this.setHardness(5.0F); + this.setStepSound(soundTypeMetal); + this.setBlockName("mobSpawner"); + this.setBlockTextureName("mob_spawner"); } /** * Returns a new instance of a block's tile entity class. Called on placing the block. */ + @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityGenericSpawner(meta); } + + @Override + public int getExpDrop(IBlockAccess world, int metadata, int fortune){ + return 15 + RANDOM.nextInt(15) + RANDOM.nextInt(15); + } + + /** + * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks) + */ + @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) + { + p_149666_3_.add(new ItemStack(p_149666_1_, 1, i)); + } + } } diff --git a/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java b/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java index 2e4e6c06d2..429ca104ac 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java +++ b/src/Java/gtPlusPlus/plugin/villagers/entity/EntityBaseVillager.java @@ -27,7 +27,7 @@ import net.minecraft.village.MerchantRecipeList; import net.minecraft.village.Village; import net.minecraft.world.World; -public abstract class EntityBaseVillager extends EntityVillager { +public class EntityBaseVillager extends EntityVillager { // public static final VillagerProfession mProfession; @@ -106,7 +106,9 @@ public abstract class EntityBaseVillager extends EntityVillager { super.setRecipes(p_70930_1_); } - public abstract boolean shouldAlwaysSprint(); + public boolean shouldAlwaysSprint() { + return false; + }; @Override public void onLivingUpdate() { diff --git a/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java b/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java index 131c97bf23..c7ffd6ee8c 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java +++ b/src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java @@ -7,42 +7,51 @@ import net.minecraft.world.World; public class MobSpawnerCustomLogic extends MobSpawnerBaseLogic { - private final TileEntity mTile; - + private TileEntity mTile; + public MobSpawnerCustomLogic(TileEntity tile) { - mTile = tile; + if (tile != null) { + mTile = tile; + } } - - + @Override - public void func_98267_a(int p_98267_1_){ - mTile.getWorldObj().addBlockEvent( - mTile.xCoord, - mTile.yCoord, - mTile.zCoord, - Blocks.mob_spawner, - p_98267_1_, - 0); - } + public void func_98267_a(int eventID) { + if (mTile != null) mTile.getWorldObj().addBlockEvent(mTile.xCoord, mTile.yCoord, mTile.zCoord, Blocks.mob_spawner, eventID, 0); + } @Override public World getSpawnerWorld() { - return mTile.getWorldObj(); + if (mTile != null) return mTile.getWorldObj(); + return null; } @Override public int getSpawnerX() { - return mTile.xCoord; + if (mTile != null) return mTile.xCoord; + return 0; } @Override public int getSpawnerY() { - return mTile.yCoord; + if (mTile != null) return mTile.yCoord; + return 0; } @Override public int getSpawnerZ() { - return mTile.zCoord; + if (mTile != null) return mTile.zCoord; + return 0; + } + + @Override + public void setRandomEntity(MobSpawnerBaseLogic.WeightedRandomMinecart p_98277_1_) { + super.setRandomEntity(p_98277_1_); + if (mTile != null) { + if (this.getSpawnerWorld() != null) { + this.getSpawnerWorld().markBlockForUpdate(mTile.xCoord, mTile.yCoord, mTile.zCoord); + } + } } } diff --git a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java index ea05525166..2dbd21dd3b 100644 --- a/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java +++ b/src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java @@ -1,75 +1,197 @@ package gtPlusPlus.plugin.villagers.tile; +import java.lang.reflect.Field; import java.util.HashMap; +import java.util.Map; +import gtPlusPlus.core.util.reflect.ReflectionUtils; import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.MobSpawnerBaseLogic; +import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityMobSpawner; public class TileEntityGenericSpawner extends TileEntityMobSpawner { - + /* * Static Variables */ - + + /** A HashMap storing string names of classes mapping to the actual java.lang.Class type. */ + private static Map nameToClassMap_Ex = new HashMap(); + /** A HashMap storing the classes and mapping to the string names (reverse of nameToClassMap). */ + private static Map classToNameMap_Ex = new HashMap(); + /** * The Mob Spawner Map */ public static HashMap<Integer, Entity> mSpawners = new HashMap<Integer, Entity>(); - + /** * Registers a New Mob Spawner Type - * @param aID - the Spawner type ID - * @param aEntity - the Entity which you'd like to spawn + * + * @param aID + * - the Spawner type ID + * @param aEntity + * - the Entity which you'd like to spawn */ public static boolean registerNewMobSpawner(int aID, Entity aEntity) { int registered = mSpawners.size(); mSpawners.put(aID, aEntity); return mSpawners.size() > registered; } - + /* * Instance Variables */ - + /** * The {@link Entity} type which spawns. */ private final Entity mSpawnType; - - - + private MobSpawnerCustomLogic spawnerLogic; + /* * Constructors */ - + /** * Constructs a new Spawner, based on an existing type registered. - * @param aID - The ID in the {@link mSpawners} map. + * + * @param aID + * - The ID in the {@link mSpawners} map. */ public TileEntityGenericSpawner(int aID) { if (mSpawners.get(aID) != null) { - mSpawnType = mSpawners.get(aID); - } - else { + mSpawnType = mSpawners.get(aID); + } else { mSpawnType = null; } - } + // Last thing to Init + generateLogicObject(); + } /** * Constructs a new Spawner, then registers it. - * @param aID - The ID to be used in the {@link mSpawners} map. - * @param aEntity - The {@link Entity} type which will be spawned. + * + * @param aID + * - The ID to be used in the {@link mSpawners} map. + * @param aEntity + * - The {@link Entity} type which will be spawned. */ public TileEntityGenericSpawner(int aID, Entity aEntity) { if (aEntity != null) { mSpawnType = aEntity; - this.registerNewMobSpawner(aID, aEntity); - } - else { + registerNewMobSpawner(aID, aEntity); + } else { mSpawnType = null; } + + // Last thing to Init + generateLogicObject(); + } + + public final MobSpawnerCustomLogic getLogic() { + if (spawnerLogic == null || spawnerLogic.getSpawnerWorld() == null) { + generateLogicObject(); + } + return spawnerLogic; + } + + private final void generateLogicObject() { + spawnerLogic = new MobSpawnerCustomLogic(this); + } + + @Override + public void readFromNBT(NBTTagCompound p_145839_1_) { + if (hasInternalFieldBeenSet()) { + this.getLogic().readFromNBT(p_145839_1_); + this.xCoord = p_145839_1_.getInteger("x"); + this.yCoord = p_145839_1_.getInteger("y"); + this.zCoord = p_145839_1_.getInteger("z"); + } + } + + @Override + public void writeToNBT(NBTTagCompound p_145841_1_) { + if (hasInternalFieldBeenSet()) { + + String s = (String) classToNameMap_Ex.get(TileEntity.class); + + if (s == null){ + throw new RuntimeException(this.getClass() + " is missing a mapping! This is a bug!"); + } + else { + p_145841_1_.setString("id", s); + p_145841_1_.setInteger("x", this.xCoord); + p_145841_1_.setInteger("y", this.yCoord); + p_145841_1_.setInteger("z", this.zCoord); + } + + + this.getLogic().writeToNBT(p_145841_1_); + } + } + + @Override + public void updateEntity() { + + + + + if (hasInternalFieldBeenSet()) { + this.getLogic().updateSpawner(); + } + } + + private boolean isReady = false; + private long mTicks = 0; + + private boolean hasInternalFieldBeenSet() { + 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 (mInternalLogicField != null) { + MobSpawnerBaseLogic a = (MobSpawnerBaseLogic) mInternalLogicField.get(this); + if (a != null) { + ReflectionUtils.setField(this, "field_145882_a", getLogic()); + if (a.equals(getLogic())) { + isReady = true; + return true; + } + } + }*/ + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { + } + return false; + } + } + + /** + * Called when a client event is received with the event number and argument, + * see World.sendClientEvent + */ + @Override + public boolean receiveClientEvent(int p_145842_1_, int p_145842_2_) { + return this.spawnerLogic.setDelayToMin(p_145842_1_) ? true : super.receiveClientEvent(p_145842_1_, p_145842_2_); + } + + @Override + public MobSpawnerBaseLogic func_145881_a() { + return this.spawnerLogic; } - } |