TechReborn/src/main/java/techreborn/tiles/TileAesu.java

164 lines
3.8 KiB
Java
Raw Normal View History

2015-05-09 21:19:40 +02:00
package techreborn.tiles;
import ic2.api.energy.EnergyNet;
2015-05-09 21:19:40 +02:00
import ic2.api.tile.IWrenchable;
import ic2.core.util.Util;
2015-05-09 21:19:40 +02:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-06-14 17:42:03 +02:00
import techreborn.blocks.storage.EUStorageTile;
2015-06-14 13:15:24 +02:00
import techreborn.config.ConfigTechReborn;
2015-05-09 21:19:40 +02:00
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import techreborn.util.LogHelper;
2015-06-14 17:42:03 +02:00
public class TileAesu extends EUStorageTile implements IWrenchable {
2015-05-09 21:19:40 +02:00
2015-05-10 22:02:57 +02:00
public static final int MAX_OUTPUT = 8192;
public static final int MAX_STORAGE = 1000000000; //One billion!
2015-05-09 21:19:40 +02:00
public Inventory inventory = new Inventory(2, "TileAesu", 64);
private int OUTPUT = 64; //The current output
private double euLastTick = 0;
2015-06-14 13:15:24 +02:00
private double euChange;
private int ticks;
2015-05-09 21:19:40 +02:00
public TileAesu()
{
2015-05-10 22:02:57 +02:00
super(5, TileAesu.MAX_OUTPUT, TileAesu.MAX_STORAGE);
2015-05-09 21:19:40 +02:00
}
@Override
public void updateEntity()
{
super.updateEntity();
2015-06-14 13:15:24 +02:00
if(ticks == ConfigTechReborn.aveargeEuOutTickTime){
euChange = -1;
ticks = 0;
2015-06-14 13:15:24 +02:00
} else {
ticks ++;
euChange += energy - euLastTick;
if(euLastTick == energy){
euChange = 0;
}
2015-06-14 13:15:24 +02:00
}
euLastTick = energy;
2015-05-09 21:19:40 +02:00
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
if(!entityPlayer.isSneaking()){
return true;
}
return false;
2015-05-09 21:19:40 +02:00
}
@Override
public short getFacing()
{
return super.getFacing();
2015-05-09 21:19:40 +02:00
}
@Override
public void setFacing(short facing)
{
2015-06-07 20:11:08 +02:00
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, facing, 2);
2015-06-10 14:54:46 +02:00
super.setFacing(facing);
2015-06-07 20:11:08 +02:00
}
2015-05-09 21:19:40 +02:00
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
if (entityPlayer.isSneaking())
{
return true;
}
return false;
2015-05-09 21:19:40 +02:00
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return getDropWithNBT();
2015-05-09 21:19:40 +02:00
}
public boolean isComplete()
{
return false;
}
2015-05-10 22:02:57 +02:00
@Override
public String getInventoryName()
{
return "AESU";
}
public void handleGuiInputFromClient(int id){
if(id == 0){
OUTPUT += 256;
}
if(id == 1){
OUTPUT += 64;
}
if(id == 2){
OUTPUT -= 64;
}
if(id == 3){
OUTPUT -= 256;
}
if(OUTPUT > MAX_OUTPUT){
OUTPUT = MAX_OUTPUT;
}
if(OUTPUT <= -1){
OUTPUT = 0;
}
2015-06-14 17:42:03 +02:00
output = OUTPUT;
2015-06-10 19:36:07 +02:00
LogHelper.debug("Set output to " + getOutput());
}
public double getEuChange(){
2015-06-14 13:15:24 +02:00
if(euChange == -1){
return -1;
}
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);
}
2015-05-09 21:19:40 +02:00
}