2015-06-14 14:35:36 +02:00
|
|
|
package techreborn.tiles.lesu;
|
|
|
|
|
|
|
|
|
|
|
|
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 17:54:49 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
2015-07-01 21:34:22 +02:00
|
|
|
import techreborn.powerSystem.TilePowerAcceptor;
|
2015-06-14 14:35:36 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public class TileLesu extends TilePowerAcceptor {//TODO wrench
|
2015-06-14 14:35:36 +02:00
|
|
|
|
|
|
|
private ArrayList<LesuNetwork> countedNetworks = new ArrayList<LesuNetwork>();
|
|
|
|
public int connectedBlocks = 0;
|
|
|
|
|
2015-06-14 17:54:49 +02:00
|
|
|
private double euLastTick = 0;
|
|
|
|
private double euChange;
|
|
|
|
private int ticks;
|
2015-08-09 12:05:32 +02:00
|
|
|
private int output;
|
|
|
|
private int maxStorage;
|
2015-06-14 17:54:49 +02:00
|
|
|
|
|
|
|
public Inventory inventory = new Inventory(2, "TileAesu", 64);
|
|
|
|
|
|
|
|
public TileLesu() {
|
2015-07-01 21:34:22 +02:00
|
|
|
super(5);
|
2015-06-14 17:54:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-14 14:35:36 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity() {
|
2015-06-14 17:54:49 +02:00
|
|
|
super.updateEntity();
|
2015-08-09 12:05:32 +02:00
|
|
|
if (worldObj.isRemote) {
|
2015-06-14 14:35:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
countedNetworks.clear();
|
|
|
|
connectedBlocks = 0;
|
2015-08-09 12:05:32 +02:00
|
|
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
|
|
|
if (worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ) instanceof TileLesuStorage) {
|
|
|
|
if (((TileLesuStorage) worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)).network != null) {
|
2015-06-14 14:35:36 +02:00
|
|
|
LesuNetwork network = ((TileLesuStorage) worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)).network;
|
2015-08-09 12:05:32 +02:00
|
|
|
if (!countedNetworks.contains(network)) {
|
|
|
|
if (network.master == null || network.master == this) {
|
2015-06-14 17:42:03 +02:00
|
|
|
connectedBlocks += network.storages.size();
|
|
|
|
countedNetworks.add(network);
|
|
|
|
network.master = this;
|
2015-08-09 12:05:32 +02:00
|
|
|
break;
|
2015-06-14 17:42:03 +02:00
|
|
|
}
|
2015-06-14 14:35:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-11 16:30:03 +01:00
|
|
|
maxStorage = ((connectedBlocks + 1) * ConfigTechReborn.lesuStoragePerBlock);
|
|
|
|
output = (connectedBlocks * ConfigTechReborn.extraOutputPerLesuBlock) + ConfigTechReborn.baseLesuOutput;
|
2015-06-14 17:54:49 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
|
2015-06-14 17:54:49 +02:00
|
|
|
euChange = -1;
|
|
|
|
ticks = 0;
|
|
|
|
} else {
|
2015-08-09 12:05:32 +02:00
|
|
|
ticks++;
|
|
|
|
if (euChange == -1) {
|
2015-06-19 19:38:08 +02:00
|
|
|
euChange = 0;
|
|
|
|
}
|
2015-07-01 21:34:22 +02:00
|
|
|
euChange += getEnergy() - euLastTick;
|
2015-08-09 12:05:32 +02:00
|
|
|
if (euLastTick == getEnergy()) {
|
2015-06-14 17:54:49 +02:00
|
|
|
euChange = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-01 21:34:22 +02:00
|
|
|
euLastTick = getEnergy();
|
2015-06-14 17:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public double getEuChange() {
|
|
|
|
if (euChange == -1) {
|
2015-06-19 19:38:08 +02:00
|
|
|
return 0;
|
2015-06-14 16:58:49 +02:00
|
|
|
}
|
2015-06-14 17:54:49 +02:00
|
|
|
return (euChange / ticks);
|
2015-06-14 14:35:36 +02:00
|
|
|
}
|
2015-07-01 21:34:22 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxPower() {
|
|
|
|
return maxStorage;
|
|
|
|
}
|
2015-07-01 21:34:22 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public boolean canAcceptEnergy(ForgeDirection direction) {
|
2015-09-19 10:31:24 +02:00
|
|
|
return Functions.getIntDirFromDirection(direction) != getRotation();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-07-01 21:34:22 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public boolean canProvideEnergy(ForgeDirection direction) {
|
2015-09-19 10:31:24 +02:00
|
|
|
return Functions.getIntDirFromDirection(direction) == getRotation();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-07-01 21:34:22 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxOutput() {
|
|
|
|
return output;
|
|
|
|
}
|
2015-07-01 21:34:22 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxInput() {
|
|
|
|
return 8192;
|
|
|
|
}
|
2015-06-14 14:35:36 +02:00
|
|
|
}
|