2015-05-09 21:19:40 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2015-06-14 13:35:28 +02:00
|
|
|
import ic2.api.energy.EnergyNet;
|
2015-05-09 21:19:40 +02:00
|
|
|
import ic2.api.tile.IWrenchable;
|
2015-05-10 22:02:57 +02:00
|
|
|
import ic2.core.block.wiring.TileEntityElectricBlock;
|
2015-06-14 13:35:28 +02:00
|
|
|
import ic2.core.util.Util;
|
2015-05-09 21:19:40 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-06-14 13:35:28 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
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;
|
2015-06-10 14:52:54 +02:00
|
|
|
import techreborn.util.LogHelper;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
2015-05-09 21:19:40 +02:00
|
|
|
|
2015-05-10 22:02:57 +02:00
|
|
|
public class TileAesu extends TileEntityElectricBlock 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);
|
2015-06-10 17:12:16 +02:00
|
|
|
private int OUTPUT = 64; //The current output
|
2015-06-14 12:58:56 +02:00
|
|
|
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:35:28 +02:00
|
|
|
|
2015-06-14 13:15:24 +02:00
|
|
|
} else {
|
|
|
|
ticks ++;
|
|
|
|
euChange += energy - euLastTick;
|
2015-06-14 13:35:28 +02:00
|
|
|
if(euLastTick == energy){
|
|
|
|
euChange = 0;
|
|
|
|
}
|
2015-06-14 13:15:24 +02:00
|
|
|
}
|
2015-06-14 13:35:28 +02:00
|
|
|
|
2015-06-14 12:58:56 +02:00
|
|
|
euLastTick = energy;
|
2015-05-09 21:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
|
|
|
|
{
|
2015-06-14 13:35:28 +02:00
|
|
|
if(!entityPlayer.isSneaking()){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-05-09 21:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getFacing()
|
|
|
|
{
|
2015-06-10 17:12:16 +02:00
|
|
|
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)
|
|
|
|
{
|
2015-05-10 18:06:08 +02:00
|
|
|
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)
|
|
|
|
{
|
2015-06-14 13:35:28 +02:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2015-06-10 14:52:54 +02:00
|
|
|
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;
|
|
|
|
}
|
2015-06-10 17:12:16 +02:00
|
|
|
if(OUTPUT <= -1){
|
2015-06-10 14:52:54 +02:00
|
|
|
OUTPUT = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO make a better way and not use reflection for this.
|
|
|
|
try {
|
|
|
|
Field field = getClass().getSuperclass().getDeclaredField("output");
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(this, OUTPUT);
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2015-06-10 19:36:07 +02:00
|
|
|
LogHelper.debug("Set output to " + getOutput());
|
2015-06-10 14:52:54 +02:00
|
|
|
}
|
|
|
|
|
2015-06-14 12:58:56 +02:00
|
|
|
public double getEuChange(){
|
2015-06-14 13:15:24 +02:00
|
|
|
if(euChange == -1){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (euChange / ticks);
|
2015-06-14 12:58:56 +02:00
|
|
|
}
|
|
|
|
|
2015-06-14 13:35:28 +02:00
|
|
|
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-06-14 12:58:56 +02:00
|
|
|
|
2015-05-09 21:19:40 +02:00
|
|
|
}
|