2015-05-09 21:19:40 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-05-12 20:16:40 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
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-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-02-24 09:18:21 +01:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-07-21 17:22:56 +02:00
|
|
|
import reborncore.common.tile.TilePowerAcceptorProducer;
|
2015-11-08 13:15:45 +01:00
|
|
|
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;
|
2016-07-21 17:22:56 +02:00
|
|
|
import techreborn.power.EnergyUtils;
|
2015-06-10 14:52:54 +02:00
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public class TileAesu extends TilePowerAcceptorProducer implements IWrenchable {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-03-28 21:51:23 +02:00
|
|
|
public static final int MAX_OUTPUT = ConfigTechReborn.AesuMaxOutput;
|
|
|
|
public static final int MAX_STORAGE = ConfigTechReborn.AesuMaxStorage;
|
2016-03-25 10:47:34 +01:00
|
|
|
public Inventory inventory = new Inventory(4, "TileAesu", 64, this);
|
|
|
|
private int OUTPUT = 64; // The current output
|
|
|
|
private double euLastTick = 0;
|
|
|
|
private double euChange;
|
|
|
|
private int ticks;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public void update() {
|
|
|
|
super.update();
|
|
|
|
if (ticks == ConfigTechReborn.AverageEuOutTickTime) {
|
2016-03-25 10:47:34 +01:00
|
|
|
euChange = -1;
|
|
|
|
ticks = 0;
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
ticks++;
|
|
|
|
euChange += getEnergy() - euLastTick;
|
2016-07-21 17:22:56 +02:00
|
|
|
if (euLastTick == getEnergy()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
euChange = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
euLastTick = getEnergy();
|
2016-07-21 17:22:56 +02:00
|
|
|
|
|
|
|
if (!worldObj.isRemote && getEnergy() > 0) {
|
|
|
|
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
|
|
|
|
for(EnumFacing facing : EnumFacing.VALUES) {
|
|
|
|
double disposed = emitEnergy(facing, maxOutput);
|
|
|
|
if(disposed != 0) {
|
|
|
|
maxOutput -= disposed;
|
|
|
|
useEnergy(disposed);
|
|
|
|
if (maxOutput == 0) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
//TODO move to RebornCore
|
|
|
|
public double emitEnergy(EnumFacing enumFacing, double amount) {
|
|
|
|
BlockPos pos = getPos().offset(enumFacing);
|
|
|
|
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
|
|
|
|
worldObj, enumFacing.getOpposite(), pos);
|
|
|
|
if(receiver != null) {
|
|
|
|
return receiver.receiveEnergy(amount, false);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
2016-03-29 21:27:23 +02:00
|
|
|
return true;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public EnumFacing getFacing() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
2016-04-03 15:34:39 +02:00
|
|
|
return entityPlayer.isSneaking();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public float getWrenchDropRate() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return getDropWithNBT();
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public boolean isComplete() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public void handleGuiInputFromClient(int id) {
|
|
|
|
if (id == 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
OUTPUT += 256;
|
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
if (id == 1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
OUTPUT += 64;
|
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
if (id == 2) {
|
2016-03-25 10:47:34 +01:00
|
|
|
OUTPUT -= 64;
|
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
if (id == 3) {
|
2016-03-25 10:47:34 +01:00
|
|
|
OUTPUT -= 256;
|
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
if (OUTPUT > MAX_OUTPUT) {
|
2016-03-25 10:47:34 +01:00
|
|
|
OUTPUT = MAX_OUTPUT;
|
|
|
|
}
|
2016-07-21 17:22:56 +02:00
|
|
|
if (OUTPUT <= -1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
OUTPUT = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public double getEuChange() {
|
|
|
|
if (euChange == -1) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return (euChange / ticks);
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public ItemStack getDropWithNBT() {
|
2016-03-25 10:47:34 +01:00
|
|
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
|
|
|
ItemStack dropStack = new ItemStack(ModBlocks.Aesu, 1);
|
|
|
|
dropStack.setTagCompound(new NBTTagCompound());
|
|
|
|
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
|
|
|
return dropStack;
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
tagCompound.setDouble("euChange", euChange);
|
|
|
|
tagCompound.setDouble("euLastTick", euLastTick);
|
|
|
|
tagCompound.setInteger("output", OUTPUT);
|
|
|
|
inventory.writeToNBT(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-07-21 17:22:56 +02:00
|
|
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(nbttagcompound);
|
|
|
|
this.euChange = nbttagcompound.getDouble("euChange");
|
|
|
|
this.euLastTick = nbttagcompound.getDouble("euLastTick");
|
|
|
|
this.OUTPUT = nbttagcompound.getInteger("output");
|
|
|
|
inventory.readFromNBT(nbttagcompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public double getMaxPower() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return TileAesu.MAX_STORAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public double getMaxOutput() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return OUTPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-21 17:22:56 +02:00
|
|
|
public EnumPowerTier getTier() {
|
|
|
|
return EnumPowerTier.INSANE;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2015-05-09 21:19:40 +02:00
|
|
|
}
|