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 /src/Java/gtPlusPlus/plugin/villagers/tile | |
| parent | ebac3516aada8378ca10b78acf0f942440934e6c (diff) | |
| download | GT5-Unofficial-97fb7abbf7954ed47eacbcfd38df03545cc0ec37.tar.gz GT5-Unofficial-97fb7abbf7954ed47eacbcfd38df03545cc0ec37.tar.bz2 GT5-Unofficial-97fb7abbf7954ed47eacbcfd38df03545cc0ec37.zip | |
% More work.
Diffstat (limited to 'src/Java/gtPlusPlus/plugin/villagers/tile')
| -rw-r--r-- | src/Java/gtPlusPlus/plugin/villagers/tile/MobSpawnerCustomLogic.java | 45 | ||||
| -rw-r--r-- | src/Java/gtPlusPlus/plugin/villagers/tile/TileEntityGenericSpawner.java | 166 |
2 files changed, 171 insertions, 40 deletions
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; } - } |
