diff options
author | Alkalus <draknyte1@hotmail.com> | 2017-08-06 17:07:32 +1000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2017-08-06 17:07:32 +1000 |
commit | 3e342a56584b3ea5775cfc2de276ecdde1996848 (patch) | |
tree | 96e6173b9be9f6241b20a8abc9d1a9db8cb56dce /src | |
parent | 86dc642d75b0f2fb5397c162bbe8df56d13c01ea (diff) | |
download | GT5-Unofficial-3e342a56584b3ea5775cfc2de276ecdde1996848.tar.gz GT5-Unofficial-3e342a56584b3ea5775cfc2de276ecdde1996848.tar.bz2 GT5-Unofficial-3e342a56584b3ea5775cfc2de276ecdde1996848.zip |
$ Made the RTG buffer it's last recipe to NBT.
% More RTG Texture tweaking.
Diffstat (limited to 'src')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java | 103 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java | 68 |
2 files changed, 125 insertions, 46 deletions
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java index bb1b7fb7ee..fb8c37db4d 100644 --- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java +++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java @@ -97,51 +97,76 @@ public class ReflectionUtils { //System. out.println(ste[ste.length-depth].getClassName()+"#"+ste[ste.length-depth].getMethodName()); return ste[depth].getMethodName(); } - - - /** - * Allows to change the state of an immutable instance. Huh?!? - */ + + + /** + * Allows to change the state of an immutable instance. Huh?!? + */ public static void setFieldValue(Class clazz, String fieldName, Object newValue) throws Exception { - Field nameField = getField(clazz, fieldName); - setValue(clazz, nameField, newValue); - } - - /** - * Allows to change the state of final statics. Huh?!? - */ - public static void setDefault(Class clazz, String fieldName, Object newValue) throws Exception { - Field staticField = clazz.getDeclaredField(fieldName); - setValue(null, staticField, newValue); - } - - /** - * - * Set the value of a field reflectively. - */ - protected static void setValue(Object owner, Field field, Object value) throws Exception { - makeModifiable(field); - field.set(owner, value); - } - + Field nameField = getField(clazz, fieldName); + setValue(clazz, nameField, newValue); + } + + /** + * Allows to change the state of final statics. Huh?!? + */ + public static void setDefault(Class clazz, String fieldName, Object newValue) throws Exception { + Field staticField = clazz.getDeclaredField(fieldName); + setValue(null, staticField, newValue); + } + + /** + * + * Set the value of a field reflectively. + */ + protected static void setValue(Object owner, Field field, Object value) throws Exception { + makeModifiable(field); + field.set(owner, value); + } + /** * Force the field to be modifiable and accessible. */ protected static void makeModifiable(Field nameField) throws Exception { - nameField.setAccessible(true); - int modifiers = nameField.getModifiers(); - Field modifierField = nameField.getClass().getDeclaredField("modifiers"); - modifiers = modifiers & ~Modifier.FINAL; - modifierField.setAccessible(true); - modifierField.setInt(nameField, modifiers); + nameField.setAccessible(true); + int modifiers = nameField.getModifiers(); + Field modifierField = nameField.getClass().getDeclaredField("modifiers"); + modifiers = modifiers & ~Modifier.FINAL; + modifierField.setAccessible(true); + modifierField.setInt(nameField, modifiers); } public static void setFinalStatic(Field field, Object newValue) throws Exception { - field.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); - } - + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, newValue); + } + + + + + + /** + * Allows to change the state of an immutable instance. Huh?!? + */ + public static void setByte(Class clazz, String fieldName, Byte newValue) throws Exception { + /*Field nameField = getField(clazz, fieldName); + nameField.setAccessible(true); + int modifiers = nameField.getModifiers(); + Field modifierField = nameField.getClass().getDeclaredField("modifiers"); + modifiers = modifiers & ~Modifier.FINAL; + modifierField.setAccessible(true); + modifierField.set(nameField, modifiers); + nameField.set(clazz, newValue);*/ + + final Field fieldA = clazz.getDeclaredField(fieldName); + fieldA.setAccessible( true ); + fieldA.setInt(clazz, newValue ); + + } + + + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java index a297be6fbe..de7299a18e 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java @@ -21,6 +21,7 @@ import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraftforge.fluids.FluidStack; public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator { @@ -57,6 +58,19 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator aNBT.setInteger("mVoltage", this.mVoltage); aNBT.setInteger("mDaysRemaining", this.mDaysRemaining); aNBT.setInteger("mDayTick", this.mDayTick); + + + if (this.mCurrentRecipe != null){ + final NBTTagList list = new NBTTagList(); + final ItemStack stack = this.mCurrentRecipe.mInputs[0]; + if(stack != null){ + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("mSlot", 0); + list.appendTag(data); + } + aNBT.setTag("mRecipeItem", list); + } } @Override @@ -67,6 +81,18 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator this.mVoltage = aNBT.getInteger("mVoltage"); this.mDaysRemaining = aNBT.getInteger("mDaysRemaining"); this.mDayTick = aNBT.getInteger("mDayTick"); + + + final NBTTagList list = aNBT.getTagList("mRecipeItem", 10); + ItemStack[] inventory = new ItemStack[1]; + for(int i = 0;i<list.tagCount();i++){ + final NBTTagCompound data = list.getCompoundTagAt(i); + final int slot = data.getInteger("mSlot"); + if((slot >= 0) && (slot < 1)){ + inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + this.mCurrentRecipe = getRecipes().findRecipe(getBaseMetaTileEntity(), false, 9223372036854775807L, null, new ItemStack[] { inventory[0] }); } public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { @@ -143,6 +169,23 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator public GregtechMetaTileEntity_RTG(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, "Requires RTG Pellets", new ITexture[0]); } + + private byte getTier(){ + int voltage = this.mVoltage; + if (voltage >= 512){ + return 4; + } + else if (voltage >= 128){ + return 3; + } + else if (voltage >= 32){ + return 2; + } + else if (voltage >= 8){ + return 1; + } + return 0; + } public GregtechMetaTileEntity_RTG(String aName, int aTier, String aDescription, ITexture[][][] aTextures) { @@ -172,7 +215,8 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator public ITexture[] getFront(byte aColor) { return new ITexture[] { super.getFront(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) }; + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE) }; } public ITexture[] getBack(byte aColor) { @@ -187,16 +231,21 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator public ITexture[] getTop(byte aColor) { return new ITexture[] { super.getTop(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) }; } public ITexture[] getSides(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) ,gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; + return new ITexture[]{ + gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()]}; } public ITexture[] getFrontActive(byte aColor) { return new ITexture[] { super.getFrontActive(aColor)[0], - new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) }; + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ASSEMBLY_LINE_ACTIVE) }; } public ITexture[] getBackActive(byte aColor) { @@ -211,11 +260,15 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator public ITexture[] getTopActive(byte aColor) { return new ITexture[] { super.getTopActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) }; } public ITexture[] getSidesActive(byte aColor) { - return new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) ,gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier]}; + return new ITexture[]{ + gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()]}; } public int getPollution() { @@ -232,10 +285,10 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator int voltage = tFuel.mEUt; this.mVoltage = voltage; int sfsf = this.mTier; - this.mDaysRemaining = tFuel.mSpecialValue*365; + //this.mDaysRemaining = tFuel.mSpecialValue*365; //Do some voodoo. - int mTier2; + byte mTier2 = 0; //mTier2 = ReflectionUtils.getField(this.getClass(), "mTier"); try { if (this.mCurrentRecipe.mInputs[0] == GregtechItemList.Pellet_RTG_AM241.get(1)){ @@ -253,7 +306,7 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator else { mTier2 = 0; } - ReflectionUtils.setFieldValue(this.getClass(), "mTier", mTier2); + ReflectionUtils.setByte(super.getClass(), "mTier", (byte) mTier2); //ReflectionUtils.setFinalStatic(mTier2, GT_Values.V[0]); } catch (Exception e) { Utils.LOG_INFO("Failed setting mTier."); @@ -265,6 +318,7 @@ public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator mTicksToBurnFor = Integer.MAX_VALUE; Utils.LOG_INFO("Fuel went over Int limit, setting to MAX_VALUE."); } + this.mDaysRemaining = MathUtils.roundToClosestInt(mTicksToBurnFor/20/60/3); return (int) (mTicksToBurnFor * getEfficiency() / 100L); //return (int) (tFuel.mSpecialValue * 365L * getEfficiency() / 100L); //return tFuel.mEUt; |