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

85 lines
2.5 KiB
Java
Raw Normal View History

2015-06-14 14:35:36 +02:00
package techreborn.tiles.lesu;
2015-06-14 17:54:49 +02:00
import ic2.api.tile.IWrenchable;
2015-06-14 14:35:36 +02:00
import net.minecraftforge.common.util.ForgeDirection;
2015-06-14 17:54:49 +02:00
import techreborn.blocks.storage.EUStorageTile;
import techreborn.config.ConfigTechReborn;
import techreborn.util.Inventory;
2015-06-14 14:35:36 +02:00
import java.util.ArrayList;
2015-06-14 17:54:49 +02:00
public class TileLesu extends EUStorageTile implements IWrenchable {
2015-06-14 14:35:36 +02:00
2015-06-14 17:54:49 +02:00
public int baseEU = 0;
public int storgeBlockSize = 1000000;
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;
public Inventory inventory = new Inventory(2, "TileAesu", 64);
public TileLesu() {
super(5, 0, 0);
}
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;
}
2015-06-14 14:35:36 +02:00
}
}
}
}
if(currentBlocks != connectedBlocks){
2015-06-14 17:42:03 +02:00
maxStorage = (connectedBlocks * storgeBlockSize) + baseEU;
2015-06-14 17:54:49 +02:00
output = connectedBlocks;
}
if(ticks == ConfigTechReborn.aveargeEuOutTickTime){
euChange = -1;
ticks = 0;
} else {
ticks ++;
euChange += energy - euLastTick;
if(euLastTick == energy){
euChange = 0;
}
}
euLastTick = energy;
}
@Override
public String getInventoryName() {
return "Lesu";
}
public double getEuChange(){
if(euChange == -1){
return -1;
}
2015-06-14 17:54:49 +02:00
return (euChange / ticks);
2015-06-14 14:35:36 +02:00
}
}