Round energy, fixed NBT, added new texture for battery when in multi block form

This commit is contained in:
Aidan Brady 2013-08-05 12:35:56 -04:00
parent b0ffec41d3
commit 9055ae71d5
6 changed files with 41 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View file

@ -15,7 +15,7 @@ public interface IBattery
{
public float getEnergyStored(ItemStack itemStack);
public float getMaxEnergyStored();
public float getMaxEnergyStored(ItemStack itemStack);
/**
* @param itemStack

View file

@ -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);
}

View file

@ -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);

View file

@ -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,11 +81,16 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
prevStructure = structure;
if(structure != null)
{
structure.wroteInventory = false;
structure.didTick = false;
}
}
@Override
public void invalidate()
{
TeslaGrid.instance().unregister(this);
super.invalidate();
}
@Override
@ -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);
}
}
}

View file

@ -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);
if(((TileEntityBattery)t).structure.isMultiblock)
{
this.func_110628_a(TEXTURE_MULTI);
}
else {
this.func_110628_a(TEXTURE);
}
MODEL.render(0.0625f);
GL11.glPopMatrix();