2015-05-09 21:19:40 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import ic2.api.tile.IWrenchable;
|
|
|
|
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-07-23 14:42:20 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.misc.Functions;
|
|
|
|
import reborncore.common.util.Inventory;
|
2015-06-14 13:15:24 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
2015-05-09 21:19:40 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-07-23 14:42:20 +02:00
|
|
|
import techreborn.powerSystem.TilePowerAcceptor;
|
2015-06-10 14:52:54 +02:00
|
|
|
|
2015-07-23 14:42:20 +02:00
|
|
|
public class TileAesu extends TilePowerAcceptor implements IWrenchable {
|
2015-05-09 21:19:40 +02:00
|
|
|
|
2015-07-21 18:53:20 +02:00
|
|
|
public static final int MAX_OUTPUT = ConfigTechReborn.aesuMaxOutput;
|
|
|
|
public static final int MAX_STORAGE = ConfigTechReborn.aesuMaxStorage;
|
2015-08-09 12:05:32 +02:00
|
|
|
public Inventory inventory = new Inventory(2, "TileAesu", 64);
|
|
|
|
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-08-09 12:05:32 +02:00
|
|
|
|
|
|
|
public TileAesu() {
|
|
|
|
super(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
|
|
|
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
|
2015-06-14 13:15:24 +02:00
|
|
|
euChange = -1;
|
|
|
|
ticks = 0;
|
2015-06-14 13:35:28 +02:00
|
|
|
|
2015-06-14 13:15:24 +02:00
|
|
|
} else {
|
2015-08-09 12:05:32 +02:00
|
|
|
ticks++;
|
2015-07-23 14:42:20 +02:00
|
|
|
euChange += getEnergy() - euLastTick;
|
2015-08-09 12:05:32 +02:00
|
|
|
if (euLastTick == getEnergy()) {
|
2015-06-14 13:35:28 +02:00
|
|
|
euChange = 0;
|
|
|
|
}
|
2015-06-14 13:15:24 +02:00
|
|
|
}
|
2015-06-14 13:35:28 +02:00
|
|
|
|
2015-07-23 14:42:20 +02:00
|
|
|
euLastTick = getEnergy();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-05-09 21:19:40 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
|
|
|
if (!entityPlayer.isSneaking()) {
|
2015-06-14 13:35:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getFacing() {
|
2015-09-19 10:31:24 +02:00
|
|
|
return (short) getRotation();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFacing(short facing) {
|
2015-09-19 10:31:24 +02:00
|
|
|
setRotation(facing);
|
2015-06-07 20:11:08 +02:00
|
|
|
}
|
2015-05-09 21:19:40 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
|
|
if (entityPlayer.isSneaking()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate() {
|
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
|
|
|
return getDropWithNBT();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isComplete() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public double getEuChange() {
|
|
|
|
if (euChange == -1) {
|
2015-06-14 13:15:24 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (euChange / ticks);
|
2015-06-14 12:58:56 +02:00
|
|
|
}
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public ItemStack getDropWithNBT() {
|
2015-06-14 13:35:28 +02:00
|
|
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
|
|
|
ItemStack dropStack = new ItemStack(ModBlocks.Aesu, 1);
|
|
|
|
writeToNBTWithoutCoords(tileEntity);
|
|
|
|
dropStack.setTagCompound(new NBTTagCompound());
|
|
|
|
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
|
|
|
|
return dropStack;
|
|
|
|
}
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
|
2015-07-23 14:42:20 +02:00
|
|
|
super.writeToNBTWithoutCoords(tagCompound);
|
2015-06-14 13:35:28 +02:00
|
|
|
tagCompound.setDouble("euChange", euChange);
|
|
|
|
tagCompound.setDouble("euLastTick", euLastTick);
|
|
|
|
inventory.writeToNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBTWithoutCoords(NBTTagCompound nbttagcompound) {
|
2015-07-23 14:42:20 +02:00
|
|
|
super.readFromNBTWithoutCoords(nbttagcompound);
|
2015-06-14 13:35:28 +02:00
|
|
|
this.euChange = nbttagcompound.getDouble("euChange");
|
|
|
|
this.euLastTick = nbttagcompound.getDouble("euLastTick");
|
|
|
|
inventory.readFromNBT(nbttagcompound);
|
|
|
|
}
|
|
|
|
|
2015-06-14 12:58:56 +02:00
|
|
|
|
2015-07-23 14:42:20 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxPower() {
|
|
|
|
return TileAesu.MAX_STORAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAcceptEnergy(ForgeDirection direction) {
|
2015-09-19 10:31:24 +02:00
|
|
|
return getRotation() != Functions.getIntDirFromDirection(direction);
|
2015-07-23 14:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canProvideEnergy(ForgeDirection direction) {
|
2015-09-19 10:31:24 +02:00
|
|
|
return getRotation() == Functions.getIntDirFromDirection(direction);
|
2015-07-23 14:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxOutput() {
|
|
|
|
return OUTPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxInput() {
|
|
|
|
return 4096 * 2;
|
|
|
|
}
|
2015-05-09 21:19:40 +02:00
|
|
|
}
|