Added lesu storage block counting

This commit is contained in:
modmuss50 2015-06-14 13:35:36 +01:00
parent 81f75abf22
commit 51c91aaccb
7 changed files with 198 additions and 28 deletions

View file

@ -2,10 +2,13 @@ package techreborn.blocks.storage;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import techreborn.blocks.BlockMachineBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import techreborn.tiles.lesu.TileLesu;
public class BlockLesu extends BlockMachineBase {
@ -45,4 +48,11 @@ public class BlockLesu extends BlockMachineBase {
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
{
return new TileLesu();
}
}

View file

@ -1,11 +1,25 @@
package techreborn.blocks.storage;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import techreborn.blocks.BlockMachineBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import techreborn.init.ModBlocks;
import techreborn.lib.Location;
import techreborn.tiles.lesu.TileLesu;
import techreborn.tiles.lesu.TileLesuStorage;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
public class BlockLesuStorage extends BlockMachineBase {
@ -45,4 +59,27 @@ public class BlockLesuStorage extends BlockMachineBase {
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack) {
super.onBlockPlacedBy(world, x, y, z, player, itemstack);
if(world.getTileEntity(x, y, z) instanceof TileLesuStorage){
((TileLesuStorage) world.getTileEntity(x, y, z)).rebuildNetwork();
}
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
super.breakBlock(world, x, y, z, block, meta);
if(world.getTileEntity(x, y, z) instanceof TileLesuStorage){
((TileLesuStorage) world.getTileEntity(x, y, z)).removeFromNetwork();
}
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
{
return new TileLesuStorage();
}
}

View file

@ -37,33 +37,9 @@ import techreborn.blocks.storage.BlockIDSU;
import techreborn.blocks.storage.BlockLesu;
import techreborn.blocks.storage.BlockLesuStorage;
import techreborn.itemblocks.*;
import techreborn.tiles.TileAesu;
import techreborn.tiles.TileAlloyFurnace;
import techreborn.tiles.TileAlloySmelter;
import techreborn.tiles.TileAssemblingMachine;
import techreborn.tiles.TileBlastFurnace;
import techreborn.tiles.TileCentrifuge;
import techreborn.tiles.TileChemicalReactor;
import techreborn.tiles.TileChunkLoader;
import techreborn.tiles.TileDieselGenerator;
import techreborn.tiles.TileDragonEggSiphoner;
import techreborn.tiles.TileGrinder;
import techreborn.tiles.TileHeatGenerator;
import techreborn.tiles.TileImplosionCompressor;
import techreborn.tiles.TileIndustrialElectrolyzer;
import techreborn.tiles.TileIndustrialSawmill;
import techreborn.tiles.TileLathe;
import techreborn.tiles.TileMachineCasing;
import techreborn.tiles.TileMatterFabricator;
import techreborn.tiles.TileMetalShelf;
import techreborn.tiles.TilePlateCuttingMachine;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileDigitalChest;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileRollingMachine;
import techreborn.tiles.TileThermalGenerator;
import techreborn.tiles.TileSemifluidGenerator;
import techreborn.tiles.TileGasTurbine;
import techreborn.tiles.*;
import techreborn.tiles.lesu.TileLesu;
import techreborn.tiles.lesu.TileLesuStorage;
import techreborn.util.LogHelper;
import cpw.mods.fml.common.registry.GameRegistry;
@ -238,6 +214,7 @@ public class ModBlocks {
Lesu = new BlockLesu(Material.rock);
GameRegistry.registerBlock(Lesu, "lesu");
GameRegistry.registerTileEntity(TileLesu.class, "TileLesuTR");
Supercondensator = new BlockSupercondensator(Material.rock);
GameRegistry.registerBlock(Supercondensator, "supercondensator");
@ -251,6 +228,7 @@ public class ModBlocks {
LesuStorage = new BlockLesuStorage(Material.rock);
GameRegistry.registerBlock(LesuStorage, "lesustorage");
GameRegistry.registerTileEntity(TileLesuStorage.class, "TileLesuStorageTR");
Distillationtower = new BlockDistillationTower(Material.rock);
GameRegistry.registerBlock(Distillationtower, "distillationtower");

View file

@ -7,7 +7,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class Location {
public class Location implements Comparable<Location> {
public int x;
public int y;
public int z;

View file

@ -0,0 +1,51 @@
package techreborn.tiles.lesu;
import java.util.ArrayList;
public class LesuNetwork {
public ArrayList<TileLesuStorage> storages = new ArrayList<TileLesuStorage>();
public void addElement(TileLesuStorage lesuStorage){
if(!storages.contains(lesuStorage)){
storages.add(lesuStorage);
}
}
public void removeElement(TileLesuStorage lesuStorage){
storages.remove(lesuStorage);
rebuild();
}
private void rebuild(){
for(TileLesuStorage lesuStorage : storages){
lesuStorage.findAndJoinNetwork(lesuStorage.getWorldObj(), lesuStorage.xCoord, lesuStorage.yCoord, lesuStorage.zCoord);
}
}
public void merge(LesuNetwork network){
if(network != this){
ArrayList<TileLesuStorage> tileLesuStorages = new ArrayList<TileLesuStorage>();
tileLesuStorages.addAll(network.storages);
network.clear(false);
for(TileLesuStorage lesuStorage : tileLesuStorages){
lesuStorage.setNetwork(this);
}
}
}
private void clear(boolean clearTiles) {
if (clearTiles) {
for(TileLesuStorage tileLesuStorage : storages){
tileLesuStorage.resetNetwork();
}
}
storages.clear();
}
public void printInfo(){
System.out.println(storages.size());
}
}

View file

@ -0,0 +1,37 @@
package techreborn.tiles.lesu;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.tiles.TileAesu;
import java.util.ArrayList;
public class TileLesu extends TileAesu {
public int baseEU = 1000000000;
public int storgeBlockSize = 100000;
private ArrayList<LesuNetwork> countedNetworks = new ArrayList<LesuNetwork>();
public int connectedBlocks = 0;
@Override
public void updateEntity() {
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)){
connectedBlocks += network.storages.size();
countedNetworks.add(network);
}
}
}
}
System.out.println(connectedBlocks);
}
}

View file

@ -0,0 +1,57 @@
package techreborn.tiles.lesu;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.tiles.TileMachineBase;
public class TileLesuStorage extends TileMachineBase {
public LesuNetwork network;
@Override
public void updateEntity() {
super.updateEntity();
if(network == null){
findAndJoinNetwork(worldObj, xCoord, yCoord, zCoord);
} else {
//network.printInfo();
}
}
public final void findAndJoinNetwork(World world, int x, int y, int z) {
network = new LesuNetwork();
network.addElement(this);
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS){
if(world.getTileEntity(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ) instanceof TileLesuStorage){
TileLesuStorage lesu = (TileLesuStorage) world.getTileEntity(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ);
if(lesu.network != null){
lesu.network.merge(network);
}
}
}
}
public final void setNetwork(LesuNetwork n) {
if (n == null) {
} else {
network = n;
network.addElement(this);
}
}
public final void resetNetwork() {
network = null;
}
public final void removeFromNetwork() {
if (network == null) {
} else
network.removeElement(this);
}
public final void rebuildNetwork() {
this.removeFromNetwork();
this.resetNetwork();
this.findAndJoinNetwork(worldObj, xCoord, yCoord, zCoord);
}
}