Machines don't NEED to be connected with cables anymore (they can be next to each other)

This commit is contained in:
Raoul Van den Berge
2016-03-25 18:55:18 +01:00
parent 108373f6eb
commit af4f3e8b40
5 changed files with 71 additions and 89 deletions

View File

@@ -1,5 +1,6 @@
package refinedstorage.block; package refinedstorage.block;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockStateContainer;
@@ -9,7 +10,8 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import refinedstorage.tile.TileCable; import refinedstorage.tile.TileController;
import refinedstorage.tile.TileMachine;
public class BlockCable extends BlockBase { public class BlockCable extends BlockBase {
public static final PropertyBool NORTH = PropertyBool.create("north"); public static final PropertyBool NORTH = PropertyBool.create("north");
@@ -40,12 +42,24 @@ public class BlockCable extends BlockBase {
@Override @Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
return super.getActualState(state, world, pos) return super.getActualState(state, world, pos)
.withProperty(NORTH, TileCable.hasConnectionWith(world, pos.north())) .withProperty(NORTH, hasConnectionWith(world, pos.north()))
.withProperty(EAST, TileCable.hasConnectionWith(world, pos.east())) .withProperty(EAST, hasConnectionWith(world, pos.east()))
.withProperty(SOUTH, TileCable.hasConnectionWith(world, pos.south())) .withProperty(SOUTH, hasConnectionWith(world, pos.south()))
.withProperty(WEST, TileCable.hasConnectionWith(world, pos.west())) .withProperty(WEST, hasConnectionWith(world, pos.west()))
.withProperty(UP, TileCable.hasConnectionWith(world, pos.up())) .withProperty(UP, hasConnectionWith(world, pos.up()))
.withProperty(DOWN, TileCable.hasConnectionWith(world, pos.down())); .withProperty(DOWN, hasConnectionWith(world, pos.down()));
}
public static boolean hasConnectionWith(IBlockAccess world, BlockPos pos) {
Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockCable) {
return true;
}
TileEntity tile = world.getTileEntity(pos);
return tile instanceof TileMachine || tile instanceof TileController;
} }
@Override @Override
@@ -60,16 +74,6 @@ public class BlockCable extends BlockBase {
return getBoundingBox(state, world, pos); return getBoundingBox(state, world, pos);
} }
@Override
public boolean hasTileEntity(IBlockState state) {
return true;
}
@Override
public TileEntity createTileEntity(World world, IBlockState state) {
return new TileCable();
}
@Override @Override
public boolean isOpaqueCube(IBlockState state) { public boolean isOpaqueCube(IBlockState state) {
return false; return false;

View File

@@ -42,7 +42,6 @@ public class CommonProxy {
NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(RefinedStorage.INSTANCE, new GuiHandler());
GameRegistry.registerTileEntity(TileController.class, ID + ":controller"); GameRegistry.registerTileEntity(TileController.class, ID + ":controller");
GameRegistry.registerTileEntity(TileCable.class, ID + ":cable");
GameRegistry.registerTileEntity(TileGrid.class, ID + ":grid"); GameRegistry.registerTileEntity(TileGrid.class, ID + ":grid");
GameRegistry.registerTileEntity(TileDiskDrive.class, ID + ":disk_drive"); GameRegistry.registerTileEntity(TileDiskDrive.class, ID + ":disk_drive");
GameRegistry.registerTileEntity(TileExternalStorage.class, ID + ":external_storage"); GameRegistry.registerTileEntity(TileExternalStorage.class, ID + ":external_storage");

View File

@@ -0,0 +1,47 @@
package refinedstorage.tile;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import refinedstorage.RefinedStorageBlocks;
import java.util.List;
public class MachineSearcher {
public static void search(TileController controller, BlockPos current, List<BlockPos> visited, List<TileMachine> machines) {
for (BlockPos visit : visited) {
if (visit.equals(current) || controller.getPos().equals(current)) {
return;
}
}
visited.add(current);
Block block = controller.getWorld().getBlockState(current).getBlock();
TileEntity tile = controller.getWorld().getTileEntity(current);
if (tile instanceof TileController) {
if (!tile.getPos().equals(controller.getPos())) {
controller.getWorld().createExplosion(null, tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), 4.5f, true);
}
}
if (tile instanceof TileMachine) {
TileMachine machine = (TileMachine) tile;
if (machine.getRedstoneMode().isEnabled(controller.getWorld(), tile.getPos())) {
machines.add(machine);
} else if (machine instanceof TileRelay) {
// If the relay is disabled we can't search any further
return;
}
}
if (tile instanceof TileMachine || block == RefinedStorageBlocks.CABLE) {
for (EnumFacing dir : EnumFacing.VALUES) {
search(controller, current.offset(dir), visited, machines);
}
}
}
}

View File

@@ -1,64 +0,0 @@
package refinedstorage.tile;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import java.util.List;
public class TileCable extends TileBase {
public static boolean hasConnectionWith(IBlockAccess world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
return tile instanceof TileCable || tile instanceof TileMachine || tile instanceof TileController;
}
public void addMachines(List<BlockPos> visited, List<TileMachine> machines, TileController controller) {
for (BlockPos visitedBlock : visited) {
if (visitedBlock.equals(pos)) {
return;
}
}
visited.add(pos);
for (EnumFacing dir : EnumFacing.VALUES) {
BlockPos newPos = pos.offset(dir);
boolean alreadyVisited = false;
for (BlockPos visitedBlock : visited) {
if (visitedBlock.equals(newPos)) {
alreadyVisited = true;
}
}
if (alreadyVisited) {
continue;
}
TileEntity tile = worldObj.getTileEntity(newPos);
if (tile instanceof TileMachine && ((TileMachine) tile).getRedstoneMode().isEnabled(worldObj, newPos)) {
machines.add((TileMachine) tile);
visited.add(newPos);
if (tile instanceof TileRelay) {
for (EnumFacing relayDir : EnumFacing.VALUES) {
TileEntity nextToRelay = worldObj.getTileEntity(newPos.offset(relayDir));
if (nextToRelay instanceof TileCable) {
((TileCable) nextToRelay).addMachines(visited, machines, controller);
}
}
}
} else if (tile instanceof TileCable) {
((TileCable) tile).addMachines(visited, machines, controller);
} else if (tile instanceof TileController && !controller.getPos().equals(newPos)) {
worldObj.createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), 4.5f, true);
}
}
}
}

View File

@@ -30,7 +30,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
private List<TileMachine> machines = new ArrayList<TileMachine>(); private List<TileMachine> machines = new ArrayList<TileMachine>();
private List<BlockPos> visitedCables = new ArrayList<BlockPos>(); private List<BlockPos> visited = new ArrayList<BlockPos>();
private EnergyStorage energy = new EnergyStorage(32000); private EnergyStorage energy = new EnergyStorage(32000);
private int energyUsage; private int energyUsage;
@@ -52,16 +52,12 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
if (!isActive()) { if (!isActive()) {
disconnectAll(); disconnectAll();
} else { } else {
visitedCables.clear(); visited.clear();
List<TileMachine> newMachines = new ArrayList<TileMachine>(); List<TileMachine> newMachines = new ArrayList<TileMachine>();
for (EnumFacing dir : EnumFacing.VALUES) { for (EnumFacing dir : EnumFacing.VALUES) {
TileEntity tile = worldObj.getTileEntity(pos.offset(dir)); MachineSearcher.search(this, pos.offset(dir), visited, newMachines);
if (tile instanceof TileCable) {
((TileCable) tile).addMachines(visitedCables, newMachines, this);
}
} }
for (TileMachine machine : machines) { for (TileMachine machine : machines) {