From fd069c9a3e4d8a5e576f685a4cd465f85f7268a8 Mon Sep 17 00:00:00 2001 From: Tom Erik Date: Tue, 5 Apr 2016 19:05:22 +0200 Subject: [PATCH] Removed wrietItemNBT and readItemNBT, always show energy stored. modified: src/main/java/refinedstorage/block/BlockController.java modified: src/main/java/refinedstorage/item/ItemBlockController.java modified: src/main/java/refinedstorage/tile/TileController.java --- .../refinedstorage/block/BlockController.java | 4 +-- .../item/ItemBlockController.java | 29 ++++++++++++++----- .../refinedstorage/tile/TileController.java | 14 ++------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/refinedstorage/block/BlockController.java b/src/main/java/refinedstorage/block/BlockController.java index 4ed554fe2..d4c231802 100755 --- a/src/main/java/refinedstorage/block/BlockController.java +++ b/src/main/java/refinedstorage/block/BlockController.java @@ -129,7 +129,7 @@ public class BlockController extends BlockBase { if(tile instanceof TileController) { TileController controller = (TileController)tile; - controller.readItemFromNBT(tag); + controller.readNBT(tag); } } } @@ -141,7 +141,7 @@ public class BlockController extends BlockBase { ItemStack stack = new ItemStack(RefinedStorageBlocks.CONTROLLER, 1, RefinedStorageBlocks.CONTROLLER.getMetaFromState(state)); NBTTagCompound tag = new NBTTagCompound(); - ((TileController) world.getTileEntity(pos)).writeItemToNBT(tag); + ((TileController) world.getTileEntity(pos)).writeNBT(tag); stack.setTagCompound(tag); drops.add(stack); diff --git a/src/main/java/refinedstorage/item/ItemBlockController.java b/src/main/java/refinedstorage/item/ItemBlockController.java index e1fc3897f..b6ed5b3f8 100644 --- a/src/main/java/refinedstorage/item/ItemBlockController.java +++ b/src/main/java/refinedstorage/item/ItemBlockController.java @@ -5,6 +5,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import refinedstorage.RefinedStorageBlocks; +import refinedstorage.block.EnumControllerType; import refinedstorage.block.EnumStorageType; import refinedstorage.tile.TileController; @@ -20,17 +21,25 @@ public class ItemBlockController extends ItemBlockBase { @Override public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean b) { + EnumControllerType type = EnumControllerType.values()[stack.getMetadata()]; - if (stack.getTagCompound() != null && stack.getTagCompound().hasKey(TileController.NBT_ENERGY)) { + int energyStored = 0; + int capacity = TileController.ENERGY_CAPACITY; + int percent = 0; + + if(type == EnumControllerType.CREATIVE) { + energyStored = capacity; + percent = 100; + } + else if (stack.getTagCompound() != null && stack.getTagCompound().hasKey(TileController.NBT_ENERGY)) { NBTTagCompound tag = stack.getTagCompound(); - int energyStored = tag.getInteger(TileController.NBT_ENERGY); - int capacity = TileController.ENERGY_CAPACITY; - int percent = (int)((float)energyStored / (capacity) * 100); - - //TODO: Format numbers ? - list.add("RF: " + energyStored + "/" + capacity + "(" + percent + "%)"); + energyStored = tag.getInteger(TileController.NBT_ENERGY); + percent = (int)((float)energyStored / (capacity) * 100); } + //TODO: Format numbers ? + list.add("RF: " + energyStored + "/" + capacity + " (" + percent + "%)"); + } @Override @@ -41,6 +50,12 @@ public class ItemBlockController extends ItemBlockBase { } public static ItemStack initNBT(ItemStack stack) { + EnumControllerType type = EnumControllerType.values()[stack.getMetadata()]; + NBTTagCompound tag = stack.getTagCompound(); + if(tag == null) tag = new NBTTagCompound(); + + tag.setInteger(TileController.NBT_ENERGY, type == EnumControllerType.CREATIVE ? TileController.ENERGY_CAPACITY : 0); + return stack; } } diff --git a/src/main/java/refinedstorage/tile/TileController.java b/src/main/java/refinedstorage/tile/TileController.java index c4a60514c..9ab8eceba 100755 --- a/src/main/java/refinedstorage/tile/TileController.java +++ b/src/main/java/refinedstorage/tile/TileController.java @@ -368,12 +368,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor readNBT(nbt); } - public void readItemFromNBT(NBTTagCompound nbt) { - readNBT(nbt); - } - - private void readNBT(NBTTagCompound nbt) - { + public void readNBT(NBTTagCompound nbt) { energy.readFromNBT(nbt); if (nbt.hasKey(RedstoneMode.NBT)) { @@ -387,12 +382,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor writeNBT(nbt); } - public void writeItemToNBT(NBTTagCompound nbt) { - writeNBT(nbt); - } - - private void writeNBT(NBTTagCompound nbt) - { + public void writeNBT(NBTTagCompound nbt) { energy.writeToNBT(nbt); nbt.setInteger(RedstoneMode.NBT, redstoneMode.id); }