TechReborn/src/main/java/techreborn/tiles/lesu/TileLesu.java

108 lines
3.2 KiB
Java
Raw Normal View History

2015-06-14 14:35:36 +02:00
package techreborn.tiles.lesu;
import net.minecraftforge.common.util.ForgeDirection;
2015-06-14 17:54:49 +02:00
import techreborn.config.ConfigTechReborn;
import techreborn.lib.Functions;
import techreborn.powerSystem.TilePowerAcceptor;
2015-06-14 17:54:49 +02:00
import techreborn.util.Inventory;
2015-06-14 14:35:36 +02:00
import java.util.ArrayList;
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;
public int currentBlocks = 0;
2015-06-14 14:35:36 +02:00
2015-06-14 17:54:49 +02:00
private double euLastTick = 0;
private double euChange;
private int ticks;
private int output;
private int maxStorage;
2015-06-14 17:54:49 +02:00
public Inventory inventory = new Inventory(2, "TileAesu", 64);
public TileLesu() {
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-06-14 14:35:36 +02:00
if(worldObj.isRemote){
return;
}
countedNetworks.clear();
connectedBlocks = 0;
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){
LesuNetwork network = ((TileLesuStorage) worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ)).network;
if(!countedNetworks.contains(network)){
2015-06-14 17:42:03 +02:00
if(network.master == null || network.master == this){
connectedBlocks += network.storages.size();
countedNetworks.add(network);
network.master = this;
break;
2015-06-14 17:42:03 +02:00
}
2015-06-14 14:35:36 +02:00
}
}
}
}
if(currentBlocks != connectedBlocks){
maxStorage = ((connectedBlocks + 1) * ConfigTechReborn.lesuStoragePerBlock);
output = (connectedBlocks * ConfigTechReborn.extraOutputPerLesuBlock) + ConfigTechReborn.baseLesuOutput;
2015-06-14 17:54:49 +02:00
}
if(ticks == ConfigTechReborn.aveargeEuOutTickTime){
euChange = -1;
ticks = 0;
} else {
ticks ++;
2015-06-19 19:38:08 +02:00
if(euChange == -1){
euChange = 0;
}
euChange += getEnergy() - euLastTick;
if(euLastTick == getEnergy()){
2015-06-14 17:54:49 +02:00
euChange = 0;
}
}
euLastTick = getEnergy();
2015-06-14 17:54:49 +02:00
}
public double getEuChange(){
if(euChange == -1){
2015-06-19 19:38:08 +02:00
return 0;
}
2015-06-14 17:54:49 +02:00
return (euChange / ticks);
2015-06-14 14:35:36 +02:00
}
@Override
public double getMaxPower() {
return maxStorage;
}
@Override
public boolean canAcceptEnergy(ForgeDirection direction) {
return Functions.getIntDirFromDirection(direction) != worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
}
@Override
public boolean canProvideEnergy(ForgeDirection direction) {
return Functions.getIntDirFromDirection(direction) == worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
}
@Override
public double getMaxOutput() {
return output;
}
@Override
public double getMaxInput() {
return 8192;
}
2015-06-14 14:35:36 +02:00
}