From fdd007504f195960f63f08527f246795903e246d Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Thu, 1 Nov 2018 21:38:31 +0100 Subject: [PATCH] Fixed network node scanning allowing multiple controllers in some cases. Fixes #2069 --- CHANGELOG.md | 1 + .../apiimpl/network/NetworkNodeGraph.java | 61 +++++++++---------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea76c3182..cd4be144a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fixed client FPS stalling when using "@" mod search in the Grid (raoulvdberge) - Fixed fluid inputs/outputs in the Pattern Grid not being set when you re-insert a Pattern with fluid inputs/outputs (raoulvdberge) - Fixed bug where the Pattern Grid doesn't update it's output slot when manually configuring a crafting pattern (raoulvdberge) +- Fixed network node scanning allowing multiple controllers in some cases (raoulvdberge) ### 1.6.9 - Fixed OpenComputers "unknown error" when using extract item API (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/NetworkNodeGraph.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/NetworkNodeGraph.java index c043405e7..0044abd9f 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/NetworkNodeGraph.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/NetworkNodeGraph.java @@ -1,20 +1,19 @@ package com.raoulvdberge.refinedstorage.apiimpl.network; import com.google.common.collect.Sets; -import com.raoulvdberge.refinedstorage.RSBlocks; import com.raoulvdberge.refinedstorage.api.network.INetwork; import com.raoulvdberge.refinedstorage.api.network.INetworkNodeGraph; import com.raoulvdberge.refinedstorage.api.network.INetworkNodeVisitor; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy; import com.raoulvdberge.refinedstorage.apiimpl.network.node.ICoverable; -import com.raoulvdberge.refinedstorage.item.itemblock.ItemBlockController; import com.raoulvdberge.refinedstorage.tile.TileController; import net.minecraft.block.state.IBlockState; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -56,6 +55,7 @@ public class NetworkNodeGraph implements INetworkNodeGraph { continue; } } + // End little hack. operator.apply(controllerWorld, pos, facing.getOpposite()); } @@ -111,23 +111,18 @@ public class NetworkNodeGraph implements INetworkNodeGraph { return controller.getWorld(); } - private void removeOtherController(World world, BlockPos otherControllerPos) { - if (!controller.getPos().equals(otherControllerPos)) { - IBlockState state = world.getBlockState(otherControllerPos); + private void dropConflictingBlock(World world, BlockPos pos) { + if (!controller.getPos().equals(pos)) { + IBlockState state = world.getBlockState(pos); - TileController otherController = (TileController) world.getTileEntity(otherControllerPos); + NonNullList drops = NonNullList.create(); + state.getBlock().getDrops(drops, world, pos, state, 0); - ItemStack stackToSpawn = ItemBlockController.createStack(new ItemStack(RSBlocks.CONTROLLER, 1, state.getBlock().getMetaFromState(state)), otherController.getEnergy().getStored()); + world.setBlockToAir(pos); - world.setBlockToAir(otherControllerPos); - - InventoryHelper.spawnItemStack( - world, - otherControllerPos.getX(), - otherControllerPos.getY(), - otherControllerPos.getZ(), - stackToSpawn - ); + for (ItemStack drop : drops) { + InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), drop); + } } } @@ -143,25 +138,27 @@ public class NetworkNodeGraph implements INetworkNodeGraph { public void apply(World world, BlockPos pos, EnumFacing side) { TileEntity tile = world.getTileEntity(pos); - if (tile != null) { - if (tile instanceof TileController) { - removeOtherController(world, pos); - } else if (tile.hasCapability(NETWORK_NODE_PROXY_CAPABILITY, side)) { - INetworkNodeProxy otherNodeProxy = NETWORK_NODE_PROXY_CAPABILITY.cast(tile.getCapability(NETWORK_NODE_PROXY_CAPABILITY, side)); - INetworkNode otherNode = otherNodeProxy.getNode(); + if (tile != null && tile.hasCapability(NETWORK_NODE_PROXY_CAPABILITY, side)) { + INetworkNodeProxy otherNodeProxy = NETWORK_NODE_PROXY_CAPABILITY.cast(tile.getCapability(NETWORK_NODE_PROXY_CAPABILITY, side)); + INetworkNode otherNode = otherNodeProxy.getNode(); - if (foundNodes.add(otherNode)) { - if (!nodes.contains(otherNode)) { - // We can't let the node connect immediately - // We can only let the node connect AFTER the nodes list has changed in the graph - // This is so that storage nodes can refresh the item/fluid cache, and the item/fluid cache will notice it then (otherwise not) - newNodes.add(otherNode); - } + // This will work for regular nodes and for controllers too since controllers are internally a INetworkNode (and return themselves in INetworkNode#getNetwork). + if (otherNode.getNetwork() != null && otherNode.getNetwork() != controller) { + dropConflictingBlock(world, tile.getPos()); + return; + } - previousNodes.remove(otherNode); - - toCheck.add(new Visitor(otherNode, world, pos, side, tile)); + if (foundNodes.add(otherNode)) { + if (!nodes.contains(otherNode)) { + // We can't let the node connect immediately + // We can only let the node connect AFTER the nodes list has changed in the graph + // This is so that storage nodes can refresh the item/fluid cache, and the item/fluid cache will notice it then (otherwise not) + newNodes.add(otherNode); } + + previousNodes.remove(otherNode); + + toCheck.add(new Visitor(otherNode, world, pos, side, tile)); } } }