diff --git a/resources/assets/resonantinduction/textures/models/battery_multi.png b/resources/assets/resonantinduction/textures/models/battery_multi.png new file mode 100644 index 00000000..58104395 Binary files /dev/null and b/resources/assets/resonantinduction/textures/models/battery_multi.png differ diff --git a/src/resonantinduction/api/IBattery.java b/src/resonantinduction/api/IBattery.java index 8fc8cb9b..e308a92d 100644 --- a/src/resonantinduction/api/IBattery.java +++ b/src/resonantinduction/api/IBattery.java @@ -15,7 +15,7 @@ public interface IBattery { public float getEnergyStored(ItemStack itemStack); - public float getMaxEnergyStored(); + public float getMaxEnergyStored(ItemStack itemStack); /** * @param itemStack diff --git a/src/resonantinduction/battery/GuiBattery.java b/src/resonantinduction/battery/GuiBattery.java index d5a00c6c..838499d6 100644 --- a/src/resonantinduction/battery/GuiBattery.java +++ b/src/resonantinduction/battery/GuiBattery.java @@ -30,7 +30,7 @@ public class GuiBattery extends GuiContainer fontRenderer.drawString("Battery", 43, 6, 0x404040); fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 0x404040); fontRenderer.drawString("Cells: " + tileEntity.clientCells + " / " + tileEntity.structure.getMaxCells(), 62, 23, 0x404040); - fontRenderer.drawString("Energy: " + tileEntity.getEnergyStored() + " / " + tileEntity.getMaxEnergyStored(), 62, 32, 0x404040); + fontRenderer.drawString("Energy: " + (int)tileEntity.getEnergyStored() + " / " + (int)tileEntity.getMaxEnergyStored(), 62, 32, 0x404040); fontRenderer.drawString("Volume: " + tileEntity.structure.getVolume(), 62, 41, 0x404040); } diff --git a/src/resonantinduction/battery/ItemCapacitor.java b/src/resonantinduction/battery/ItemCapacitor.java index 1d64fa9f..310dcd38 100644 --- a/src/resonantinduction/battery/ItemCapacitor.java +++ b/src/resonantinduction/battery/ItemCapacitor.java @@ -31,7 +31,7 @@ public class ItemCapacitor extends ItemBase implements IBattery public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { double energyStored = this.getEnergyStored(itemStack); - par3List.add("Energy: " + energyStored + " KJ"); + par3List.add("Energy: " + (int)energyStored + " KJ"); } @Override @@ -41,8 +41,9 @@ public class ItemCapacitor extends ItemBase implements IBattery { itemStack.setTagCompound(new NBTTagCompound()); } + itemStack.getTagCompound().setFloat("energyStored", amount); - itemStack.setItemDamage((int) (amount / this.getMaxEnergyStored())); + itemStack.setItemDamage((int)(100 - (amount / getMaxEnergyStored(itemStack)) * 100)); } @Override @@ -52,11 +53,15 @@ public class ItemCapacitor extends ItemBase implements IBattery { itemStack.setTagCompound(new NBTTagCompound()); } - return itemStack.getTagCompound().getFloat("energyStored"); + + float amount = itemStack.getTagCompound().getFloat("energyStored"); + itemStack.setItemDamage((int)(100 - (amount / getMaxEnergyStored(itemStack)) * 100)); + + return amount; } @Override - public float getMaxEnergyStored() + public float getMaxEnergyStored(ItemStack itemStack) { return 10; } @@ -65,7 +70,7 @@ public class ItemCapacitor extends ItemBase implements IBattery public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) { ItemStack chargedStack = new ItemStack(par1, 1, 0); - this.setEnergyStored(chargedStack, this.getMaxEnergyStored()); + this.setEnergyStored(chargedStack, this.getMaxEnergyStored(chargedStack)); par3List.add(chargedStack); ItemStack unchargedStack = new ItemStack(par1, 1, 0); this.setEnergyStored(unchargedStack, 0); diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index 65a12785..9cb7903b 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -18,6 +18,7 @@ import resonantinduction.api.ITesla; import resonantinduction.base.IPacketReceiver; import resonantinduction.base.ListUtil; import resonantinduction.base.TileEntityBase; +import resonantinduction.tesla.TeslaGrid; import com.google.common.io.ByteArrayDataInput; @@ -41,6 +42,11 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver { ticks++; + if(ticks == 1) + { + TeslaGrid.instance().register(this); + } + if(!worldObj.isRemote) { if(playersUsing.size() > 0) @@ -75,13 +81,18 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver prevStructure = structure; - if(structure != null) - { - structure.didTick = false; - } + structure.wroteInventory = false; + structure.didTick = false; } } + @Override + public void invalidate() + { + TeslaGrid.instance().unregister(this); + super.invalidate(); + } + @Override public void readFromNBT(NBTTagCompound nbtTags) { @@ -207,7 +218,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver IBattery battery = (IBattery)itemStack.getItem(); float needed = amount-added; - float itemAdd = Math.min(battery.getMaxEnergyStored()-battery.getEnergyStored(itemStack), needed); + float itemAdd = Math.min(battery.getMaxEnergyStored(itemStack)-battery.getEnergyStored(itemStack), needed); if(doAdd) { @@ -273,7 +284,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver { if (itemStack.getItem() instanceof IBattery) { - max += ((IBattery) itemStack.getItem()).getMaxEnergyStored(); + max += ((IBattery) itemStack.getItem()).getMaxEnergyStored(itemStack); } } } diff --git a/src/resonantinduction/render/RenderBattery.java b/src/resonantinduction/render/RenderBattery.java index 9d5fdfad..faa3b3a1 100644 --- a/src/resonantinduction/render/RenderBattery.java +++ b/src/resonantinduction/render/RenderBattery.java @@ -22,6 +22,7 @@ import net.minecraftforge.common.ForgeDirection; import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; +import resonantinduction.battery.TileEntityBattery; import resonantinduction.model.ModelBattery; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -34,6 +35,8 @@ import cpw.mods.fml.relauncher.SideOnly; public class RenderBattery extends TileEntitySpecialRenderer { public static final ResourceLocation TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "battery.png"); + public static final ResourceLocation TEXTURE_MULTI = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "battery_multi.png"); + public static final ModelBattery MODEL = new ModelBattery(); private EntityItem fakeBattery; private Random random = new Random(); @@ -56,7 +59,15 @@ public class RenderBattery extends TileEntitySpecialRenderer GL11.glPushMatrix(); GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); - this.func_110628_a(TEXTURE); + + if(((TileEntityBattery)t).structure.isMultiblock) + { + this.func_110628_a(TEXTURE_MULTI); + } + else { + this.func_110628_a(TEXTURE); + } + MODEL.render(0.0625f); GL11.glPopMatrix();