Now stores eu when broken with a wrench. Added empty and full ones to creative tab.

This commit is contained in:
modmuss50 2015-06-14 12:35:28 +01:00
parent 63fa58eb24
commit af9e9e535a
3 changed files with 134 additions and 3 deletions

View file

@ -1,9 +1,12 @@
package techreborn.tiles;
import ic2.api.energy.EnergyNet;
import ic2.api.tile.IWrenchable;
import ic2.core.block.wiring.TileEntityElectricBlock;
import ic2.core.util.Util;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
@ -33,17 +36,25 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
if(ticks == ConfigTechReborn.aveargeEuOutTickTime){
euChange = -1;
ticks = 0;
} else {
ticks ++;
euChange += energy - euLastTick;
if(euLastTick == energy){
euChange = 0;
}
}
euLastTick = energy;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return true;
if(!entityPlayer.isSneaking()){
return true;
}
return false;
}
@Override
@ -78,7 +89,7 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.Aesu, 1);
return getDropWithNBT();
}
public boolean isComplete()
@ -133,5 +144,33 @@ public class TileAesu extends TileEntityElectricBlock implements IWrenchable {
return (euChange / ticks);
}
public ItemStack getDropWithNBT()
{
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.Aesu, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound)
{
tagCompound.setDouble("energy", this.energy);
tagCompound.setDouble("euChange", euChange);
tagCompound.setDouble("euLastTick", euLastTick);
tagCompound.setBoolean("active", this.getActive());
tagCompound.setByte("redstoneMode", this.redstoneMode);
inventory.writeToNBT(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound nbttagcompound) {
this.energy = Util.limit(nbttagcompound.getDouble("energy"), 0.0D, (double) this.maxStorage + EnergyNet.instance.getPowerFromTier(this.tier));
this.redstoneMode = nbttagcompound.getByte("redstoneMode");
this.euChange = nbttagcompound.getDouble("euChange");
this.euLastTick = nbttagcompound.getDouble("euLastTick");
inventory.readFromNBT(nbttagcompound);
}
}