Very unstable improved machine searching
This commit is contained in:
@@ -8,6 +8,7 @@ import net.minecraft.block.properties.PropertyDirection;
|
|||||||
import net.minecraft.block.state.BlockStateContainer;
|
import net.minecraft.block.state.BlockStateContainer;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
@@ -132,6 +133,22 @@ public abstract class BlockBase extends Block {
|
|||||||
super.breakBlock(world, pos, state);
|
super.breakBlock(world, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
||||||
|
if (willHarvest) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.removedByPlayer(state, world, pos, player, willHarvest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity tile, ItemStack stack) {
|
||||||
|
super.harvestBlock(world, player, pos, state, tile, stack);
|
||||||
|
|
||||||
|
world.setBlockToAir(pos);
|
||||||
|
}
|
||||||
|
|
||||||
public Item createItemForBlock() {
|
public Item createItemForBlock() {
|
||||||
return new ItemBlockBase(this, false);
|
return new ItemBlockBase(this, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,22 +93,6 @@ public class BlockController extends BlockBase {
|
|||||||
super.breakBlock(world, pos, state);
|
super.breakBlock(world, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
|
|
||||||
if (willHarvest) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.removedByPlayer(state, world, pos, player, willHarvest);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity tile, ItemStack stack) {
|
|
||||||
super.harvestBlock(world, player, pos, state, tile, stack);
|
|
||||||
|
|
||||||
world.setBlockToAir(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) {
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemStack) {
|
||||||
super.onBlockPlacedBy(world, pos, state, player, itemStack);
|
super.onBlockPlacedBy(world, pos, state, player, itemStack);
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
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;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
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 refinedstorage.tile.TileMachine;
|
import refinedstorage.tile.TileMachine;
|
||||||
|
|
||||||
public abstract class BlockMachine extends BlockBase {
|
public abstract class BlockMachine extends BlockBase {
|
||||||
@@ -33,4 +37,39 @@ public abstract class BlockMachine extends BlockBase {
|
|||||||
return super.getActualState(state, world, pos)
|
return super.getActualState(state, world, pos)
|
||||||
.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
|
.withProperty(CONNECTED, ((TileMachine) world.getTileEntity(pos)).isConnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
||||||
|
super.breakBlock(world, pos, state);
|
||||||
|
|
||||||
|
if (!world.isRemote) {
|
||||||
|
TileMachine machine = (TileMachine) world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (machine.isConnected()) {
|
||||||
|
machine.onDisconnected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
|
||||||
|
super.onBlockPlacedBy(world, pos, state, player, stack);
|
||||||
|
|
||||||
|
if (!world.isRemote) {
|
||||||
|
((TileMachine) world.getTileEntity(pos)).searchController();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock) {
|
||||||
|
super.onNeighborBlockChange(world, pos, state, neighborBlock);
|
||||||
|
|
||||||
|
if (!world.isRemote) {
|
||||||
|
TileMachine machine = (TileMachine) world.getTileEntity(pos);
|
||||||
|
|
||||||
|
if (!machine.isConnected()) {
|
||||||
|
machine.searchController();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class MessageWirelessGridCraftingStart extends MessageHandlerPlayerToServ
|
|||||||
public void handle(MessageWirelessGridCraftingStart message, EntityPlayerMP player) {
|
public void handle(MessageWirelessGridCraftingStart message, EntityPlayerMP player) {
|
||||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ));
|
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ));
|
||||||
|
|
||||||
if (tile instanceof TileController && ((TileController) tile).isActive()) {
|
if (tile instanceof TileController && ((TileController) tile).canRun()) {
|
||||||
((TileController) tile).onCraftingRequested(message.id, message.quantity);
|
((TileController) tile).onCraftingRequested(message.id, message.quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class MessageWirelessGridStoragePull extends MessageHandlerPlayerToServer
|
|||||||
public void handle(MessageWirelessGridStoragePull message, EntityPlayerMP player) {
|
public void handle(MessageWirelessGridStoragePull message, EntityPlayerMP player) {
|
||||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ));
|
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ));
|
||||||
|
|
||||||
if (tile instanceof TileController && ((TileController) tile).isActive()) {
|
if (tile instanceof TileController && ((TileController) tile).canRun()) {
|
||||||
((TileController) tile).handleStoragePull(message.id, message.flags, player);
|
((TileController) tile).handleStoragePull(message.id, message.flags, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class MessageWirelessGridStoragePush extends MessageHandlerPlayerToServer
|
|||||||
public void handle(MessageWirelessGridStoragePush message, EntityPlayerMP player) {
|
public void handle(MessageWirelessGridStoragePush message, EntityPlayerMP player) {
|
||||||
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ));
|
TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.controllerX, message.controllerY, message.controllerZ));
|
||||||
|
|
||||||
if (tile instanceof TileController && ((TileController) tile).isActive()) {
|
if (tile instanceof TileController && ((TileController) tile).canRun()) {
|
||||||
((TileController) tile).handleStoragePush(message.playerSlot, message.one, player);
|
((TileController) tile).handleStoragePush(message.playerSlot, message.one, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/main/java/refinedstorage/tile/ControllerSearcher.java
Executable file
40
src/main/java/refinedstorage/tile/ControllerSearcher.java
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
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 net.minecraft.world.World;
|
||||||
|
import refinedstorage.RefinedStorageBlocks;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ControllerSearcher {
|
||||||
|
public static TileController search(World world, BlockPos current, Set<String> visited) {
|
||||||
|
if (visited.contains(current.getX() + "," + current.getY() + "," + current.getZ())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
visited.add(current.getX() + "," + current.getY() + "," + current.getZ());
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity(current);
|
||||||
|
|
||||||
|
if (tile instanceof TileController) {
|
||||||
|
return (TileController) tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = world.getBlockState(current).getBlock();
|
||||||
|
|
||||||
|
if (tile instanceof TileMachine || block == RefinedStorageBlocks.CABLE) {
|
||||||
|
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||||
|
TileController controller = search(world, current.offset(dir), visited);
|
||||||
|
|
||||||
|
if (controller != null) {
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
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;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class MachineSearcher {
|
|
||||||
public static void search(TileController controller, BlockPos current, Set<String> visited, List<TileMachine> machines) {
|
|
||||||
if (visited.contains(current.getX() + "," + current.getY() + "," + current.getZ()) || controller.getPos().equals(current)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
visited.add(current.getX() + "," + current.getY() + "," + current.getZ());
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ import net.minecraft.inventory.Container;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -54,11 +53,14 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
private List<ItemGroup> itemGroups = new ArrayList<ItemGroup>();
|
private List<ItemGroup> itemGroups = new ArrayList<ItemGroup>();
|
||||||
private List<IStorage> storages = new ArrayList<IStorage>();
|
private List<IStorage> storages = new ArrayList<IStorage>();
|
||||||
private List<WirelessGridConsumer> wirelessGridConsumers = new ArrayList<WirelessGridConsumer>();
|
private List<WirelessGridConsumer> wirelessGridConsumers = new ArrayList<WirelessGridConsumer>();
|
||||||
private List<WirelessGridConsumer> wirelessGridConsumersMarkedForRemoval = new ArrayList<WirelessGridConsumer>();
|
private List<WirelessGridConsumer> wirelessGridConsumersToRemove = new ArrayList<WirelessGridConsumer>();
|
||||||
|
|
||||||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||||
|
|
||||||
private List<TileMachine> machines = new ArrayList<TileMachine>();
|
private List<TileMachine> machines = new ArrayList<TileMachine>();
|
||||||
|
private List<TileMachine> machinesToAdd = new ArrayList<TileMachine>();
|
||||||
|
private List<TileMachine> machinesToRemove = new ArrayList<TileMachine>();
|
||||||
|
|
||||||
private List<ClientSideMachine> clientSideMachines = new ArrayList<ClientSideMachine>();
|
private List<ClientSideMachine> clientSideMachines = new ArrayList<ClientSideMachine>();
|
||||||
|
|
||||||
private List<CraftingPattern> patterns = new ArrayList<CraftingPattern>();
|
private List<CraftingPattern> patterns = new ArrayList<CraftingPattern>();
|
||||||
@@ -66,58 +68,46 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<ICraftingTask>();
|
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<ICraftingTask>();
|
||||||
private List<ICraftingTask> craftingTasksToCancel = new ArrayList<ICraftingTask>();
|
private List<ICraftingTask> craftingTasksToCancel = new ArrayList<ICraftingTask>();
|
||||||
|
|
||||||
private Set<String> visited = new HashSet<String>();
|
|
||||||
|
|
||||||
private EnergyStorage energy = new EnergyStorage(ENERGY_CAPACITY);
|
private EnergyStorage energy = new EnergyStorage(ENERGY_CAPACITY);
|
||||||
private int energyUsage;
|
private int energyUsage;
|
||||||
|
|
||||||
private int wirelessGridRange;
|
private int wirelessGridRange;
|
||||||
|
|
||||||
private boolean destroyed = false;
|
|
||||||
|
|
||||||
private long lastEnergyRender;
|
private long lastEnergyRender;
|
||||||
|
|
||||||
private boolean machinesHavePosition(List<TileMachine> machines, BlockPos pos) {
|
public void addMachine(TileMachine machine) {
|
||||||
for (TileEntity machine : machines) {
|
machinesToAdd.add(machine);
|
||||||
if (machine.getPos().getX() == pos.getX() && machine.getPos().getY() == pos.getY() && machine.getPos().getZ() == pos.getZ()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
public void removeMachine(TileMachine machine) {
|
||||||
|
machinesToRemove.add(machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
if (!worldObj.isRemote && !destroyed) {
|
if (!worldObj.isRemote) {
|
||||||
|
if (!canRun()) {
|
||||||
|
disconnectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
machines.addAll(machinesToAdd);
|
||||||
|
machinesToAdd.clear();
|
||||||
|
|
||||||
|
machines.removeAll(machinesToRemove);
|
||||||
|
machinesToRemove.clear();
|
||||||
|
|
||||||
int lastEnergy = energy.getEnergyStored();
|
int lastEnergy = energy.getEnergyStored();
|
||||||
|
|
||||||
if (ticks % 20 == 0) {
|
|
||||||
if (!isActive()) {
|
|
||||||
disconnectAll();
|
|
||||||
} else {
|
|
||||||
visited.clear();
|
|
||||||
|
|
||||||
List<TileMachine> newMachines = new ArrayList<TileMachine>();
|
|
||||||
|
|
||||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
|
||||||
MachineSearcher.search(this, pos.offset(dir), visited, newMachines);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TileMachine machine : machines) {
|
|
||||||
if (!machinesHavePosition(newMachines, machine.getPos())) {
|
|
||||||
machine.onDisconnected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int newWirelessGridRange = 0;
|
int newWirelessGridRange = 0;
|
||||||
int newEnergyUsage = 0;
|
int newEnergyUsage = 10;
|
||||||
List<IStorage> newStorages = new ArrayList<IStorage>();
|
List<IStorage> newStorages = new ArrayList<IStorage>();
|
||||||
List<CraftingPattern> newPatterns = new ArrayList<CraftingPattern>();
|
List<CraftingPattern> newPatterns = new ArrayList<CraftingPattern>();
|
||||||
|
|
||||||
for (TileMachine machine : newMachines) {
|
for (TileMachine machine : machines) {
|
||||||
|
machine.updateMachine();
|
||||||
|
|
||||||
if (machine instanceof TileWirelessTransmitter) {
|
if (machine instanceof TileWirelessTransmitter) {
|
||||||
newWirelessGridRange += ((TileWirelessTransmitter) machine).getRange();
|
newWirelessGridRange += ((TileWirelessTransmitter) machine).getRange();
|
||||||
}
|
}
|
||||||
@@ -130,7 +120,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
TileCrafter crafter = (TileCrafter) machine;
|
TileCrafter crafter = (TileCrafter) machine;
|
||||||
|
|
||||||
for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) {
|
for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) {
|
||||||
if (crafter.getStackInSlot(i) != null) {
|
if (crafter.getStackInSlot(i) == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack pattern = crafter.getStackInSlot(i);
|
ItemStack pattern = crafter.getStackInSlot(i);
|
||||||
|
|
||||||
newPatterns.add(new CraftingPattern(
|
newPatterns.add(new CraftingPattern(
|
||||||
@@ -142,26 +135,12 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
ItemPattern.getOutputs(pattern)));
|
ItemPattern.getOutputs(pattern)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newEnergyUsage += machine.getEnergyUsage();
|
newEnergyUsage += machine.getEnergyUsage();
|
||||||
|
|
||||||
if (!machinesHavePosition(machines, machine.getPos())) {
|
|
||||||
machine.onConnected(this);
|
|
||||||
} else {
|
|
||||||
/* This machine is in our machine list, but due to a chunk reload the tile entity
|
|
||||||
would get reset which causes its connected property to reset too (to false).
|
|
||||||
So, if the machine is in our list but not connected (which is the case due to a TE reload)
|
|
||||||
we connect it either way. */
|
|
||||||
if (!machine.isConnected()) {
|
|
||||||
machine.onConnected(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wirelessGridRange = newWirelessGridRange;
|
wirelessGridRange = newWirelessGridRange;
|
||||||
energyUsage = newEnergyUsage;
|
energyUsage = newEnergyUsage;
|
||||||
machines = newMachines;
|
|
||||||
storages = newStorages;
|
storages = newStorages;
|
||||||
patterns = newPatterns;
|
patterns = newPatterns;
|
||||||
|
|
||||||
@@ -177,8 +156,6 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
});
|
});
|
||||||
|
|
||||||
syncItems();
|
syncItems();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
|
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
|
||||||
taskToCancel.onCancelled(this);
|
taskToCancel.onCancelled(this);
|
||||||
@@ -202,7 +179,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isActive()) {
|
if (canRun()) {
|
||||||
switch (getType()) {
|
switch (getType()) {
|
||||||
case NORMAL:
|
case NORMAL:
|
||||||
energy.extractEnergy(energyUsage, false);
|
energy.extractEnergy(energyUsage, false);
|
||||||
@@ -213,8 +190,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wirelessGridConsumers.removeAll(wirelessGridConsumersMarkedForRemoval);
|
wirelessGridConsumers.removeAll(wirelessGridConsumersToRemove);
|
||||||
wirelessGridConsumersMarkedForRemoval.clear();
|
wirelessGridConsumersToRemove.clear();
|
||||||
|
|
||||||
Iterator<WirelessGridConsumer> gridConsumerIterator = wirelessGridConsumers.iterator();
|
Iterator<WirelessGridConsumer> gridConsumerIterator = wirelessGridConsumers.iterator();
|
||||||
|
|
||||||
@@ -224,7 +201,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
if (!RefinedStorageUtils.compareStack(consumer.getWirelessGrid(), consumer.getPlayer().getHeldItem(consumer.getHand()))) {
|
if (!RefinedStorageUtils.compareStack(consumer.getWirelessGrid(), consumer.getPlayer().getHeldItem(consumer.getHand()))) {
|
||||||
consumer.getPlayer().closeScreen(); // This will call onContainerClosed on the Container and remove it from the list
|
consumer.getPlayer().closeScreen(); // This will call onContainerClosed on the Container and remove it from the list
|
||||||
} else {
|
} else {
|
||||||
if (isActive()) {
|
if (canRun()) {
|
||||||
RefinedStorage.NETWORK.sendTo(new MessageWirelessGridItems(this), (EntityPlayerMP) consumer.getPlayer());
|
RefinedStorage.NETWORK.sendTo(new MessageWirelessGridItems(this), (EntityPlayerMP) consumer.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,8 +227,6 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
public void onDestroyed() {
|
public void onDestroyed() {
|
||||||
disconnectAll();
|
disconnectAll();
|
||||||
|
|
||||||
destroyed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disconnectAll() {
|
private void disconnectAll() {
|
||||||
@@ -448,7 +423,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
WirelessGridConsumer consumer = getWirelessGridConsumer(player);
|
WirelessGridConsumer consumer = getWirelessGridConsumer(player);
|
||||||
|
|
||||||
if (consumer != null) {
|
if (consumer != null) {
|
||||||
wirelessGridConsumersMarkedForRemoval.add(consumer);
|
wirelessGridConsumersToRemove.add(consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,7 +530,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean canRun() {
|
||||||
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos);
|
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,7 +607,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendContainerData(ByteBuf buf) {
|
public void sendContainerData(ByteBuf buf) {
|
||||||
buf.writeInt(isActive() ? energyUsage : 0);
|
buf.writeInt(canRun() ? energyUsage : 0);
|
||||||
|
|
||||||
buf.writeInt(redstoneMode.id);
|
buf.writeInt(redstoneMode.id);
|
||||||
|
|
||||||
|
|||||||
@@ -1,62 +1,65 @@
|
|||||||
package refinedstorage.tile;
|
package refinedstorage.tile;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import refinedstorage.block.BlockMachine;
|
import refinedstorage.block.BlockMachine;
|
||||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||||
import refinedstorage.tile.config.RedstoneMode;
|
import refinedstorage.tile.config.RedstoneMode;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeConfig {
|
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeConfig {
|
||||||
protected boolean connected = false;
|
protected boolean connected = false;
|
||||||
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
protected RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||||
protected TileController controller;
|
protected TileController controller;
|
||||||
|
|
||||||
private Block machineBlock;
|
private Set<String> visited = new HashSet<String>();
|
||||||
|
|
||||||
public void onConnected(TileController controller) {
|
|
||||||
if (worldObj != null && worldObj.getBlockState(pos).getBlock() == machineBlock) {
|
|
||||||
markDirty();
|
|
||||||
|
|
||||||
this.connected = true;
|
|
||||||
this.controller = controller;
|
|
||||||
|
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDisconnected() {
|
|
||||||
if (worldObj != null && worldObj.getBlockState(pos).getBlock() == machineBlock) {
|
|
||||||
markDirty();
|
|
||||||
|
|
||||||
this.connected = false;
|
|
||||||
this.controller = null;
|
|
||||||
|
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileController getController() {
|
public TileController getController() {
|
||||||
return controller;
|
return controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void searchController() {
|
||||||
|
visited.clear();
|
||||||
|
|
||||||
|
TileController newController = ControllerSearcher.search(worldObj, pos, visited);
|
||||||
|
|
||||||
|
if (newController != null) {
|
||||||
|
this.controller = newController;
|
||||||
|
|
||||||
|
onConnected();
|
||||||
|
} else if (this.controller != null) {
|
||||||
|
this.controller = null;
|
||||||
|
|
||||||
|
onDisconnected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void onLoad() {
|
||||||
if (worldObj == null) {
|
super.onLoad();
|
||||||
super.update();
|
|
||||||
return;
|
if (!worldObj.isRemote && !connected) {
|
||||||
|
searchController();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticks == 0) {
|
public void onConnected() {
|
||||||
machineBlock = worldObj.getBlockState(pos).getBlock();
|
connected = true;
|
||||||
|
|
||||||
|
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
||||||
|
|
||||||
|
controller.addMachine(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.update();
|
public void onDisconnected() {
|
||||||
|
connected = false;
|
||||||
|
|
||||||
if (!worldObj.isRemote && isConnected()) {
|
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
||||||
updateMachine();
|
|
||||||
}
|
controller.removeMachine(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
|
|||||||
Reference in New Issue
Block a user