Check if multipart can conduct network signal
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package refinedstorage.api.network;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -56,9 +57,10 @@ public interface INetworkNode {
|
||||
boolean canUpdate();
|
||||
|
||||
/**
|
||||
* @param direction The direction to conduct to
|
||||
* @return Whether this node can conduct a network signal
|
||||
*/
|
||||
boolean canConduct();
|
||||
boolean canConduct(EnumFacing direction);
|
||||
|
||||
/**
|
||||
* @return The network
|
||||
|
||||
@@ -99,8 +99,8 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
||||
}
|
||||
}
|
||||
|
||||
if (node.canConduct()) {
|
||||
for (EnumFacing facing : EnumFacing.VALUES) {
|
||||
if (node.canConduct(facing)) {
|
||||
BlockPos pos = currentPos.offset(facing);
|
||||
|
||||
if (checked.add(pos)) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package refinedstorage.block;
|
||||
|
||||
import mcmultipart.block.BlockCoverable;
|
||||
import mcmultipart.block.BlockMultipartContainer;
|
||||
import mcmultipart.microblock.IMicroblock;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyDirection;
|
||||
@@ -96,12 +95,12 @@ public class BlockCable extends BlockCoverable {
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
|
||||
state = super.getActualState(state, world, pos)
|
||||
.withProperty(NORTH, hasConnectionWith(world, pos, pos.north()))
|
||||
.withProperty(EAST, hasConnectionWith(world, pos, pos.east()))
|
||||
.withProperty(SOUTH, hasConnectionWith(world, pos, pos.south()))
|
||||
.withProperty(WEST, hasConnectionWith(world, pos, pos.west()))
|
||||
.withProperty(UP, hasConnectionWith(world, pos, pos.up()))
|
||||
.withProperty(DOWN, hasConnectionWith(world, pos, pos.down()));
|
||||
.withProperty(NORTH, hasConnectionWith(world, pos, EnumFacing.NORTH))
|
||||
.withProperty(EAST, hasConnectionWith(world, pos, EnumFacing.EAST))
|
||||
.withProperty(SOUTH, hasConnectionWith(world, pos, EnumFacing.SOUTH))
|
||||
.withProperty(WEST, hasConnectionWith(world, pos, EnumFacing.WEST))
|
||||
.withProperty(UP, hasConnectionWith(world, pos, EnumFacing.UP))
|
||||
.withProperty(DOWN, hasConnectionWith(world, pos, EnumFacing.DOWN));
|
||||
|
||||
if (getPlacementType() != null) {
|
||||
state = state.withProperty(DIRECTION, ((TileNode) world.getTileEntity(pos)).getDirection());
|
||||
@@ -110,24 +109,16 @@ public class BlockCable extends BlockCoverable {
|
||||
return state;
|
||||
}
|
||||
|
||||
private boolean hasConnectionWith(IBlockAccess world, BlockPos basePos, BlockPos pos) {
|
||||
TileMultipartNode baseTile = (TileMultipartNode) world.getTileEntity(basePos);
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
private boolean hasConnectionWith(IBlockAccess world, BlockPos pos, EnumFacing direction) {
|
||||
TileEntity facing = world.getTileEntity(pos.offset(direction));
|
||||
|
||||
if (tile instanceof INetworkMaster || tile instanceof INetworkNode) {
|
||||
// Do not render a cable extension if the tile is blocked by a multipart
|
||||
for (IMicroblock microblock : baseTile.getMicroblockContainer().getParts()) {
|
||||
if (microblock instanceof IMicroblock.IFaceMicroblock && baseTile.getPos().offset(((IMicroblock.IFaceMicroblock) microblock).getFace()).equals(pos)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not render a cable extension to on this position when we have a direction (like an exporter, importer or external storage)
|
||||
if (facing instanceof INetworkMaster || facing instanceof INetworkNode) {
|
||||
/*// Do not render a cable extension to on this position when we have a direction (like an exporter, importer or external storage)
|
||||
if (getPlacementType() != null) {
|
||||
return baseTile.getFacingTile() != tile;
|
||||
}
|
||||
return tile.getFacingTile() != facing;
|
||||
}*/
|
||||
|
||||
return true;
|
||||
return !TileMultipartNode.hasBlockingMicroblock(world, pos, direction);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -171,12 +162,17 @@ public class BlockCable extends BlockCoverable {
|
||||
((TileBase) world.getTileEntity(pos)).setDirection(state.getValue(DIRECTION));
|
||||
}
|
||||
|
||||
attemptConnect(world, pos);
|
||||
}
|
||||
|
||||
public void attemptConnect(World world, BlockPos pos) {
|
||||
if (!world.isRemote) {
|
||||
for (EnumFacing facing : EnumFacing.VALUES) {
|
||||
TileEntity tile = world.getTileEntity(pos.offset(facing));
|
||||
|
||||
if (tile instanceof TileNode && ((TileNode) tile).isConnected()) {
|
||||
NetworkUtils.rebuildGraph(((TileNode) tile).getNetwork());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,18 @@ import mcmultipart.microblock.IMicroblock;
|
||||
import mcmultipart.microblock.IMicroblockContainerTile;
|
||||
import mcmultipart.microblock.MicroblockContainer;
|
||||
import mcmultipart.multipart.IMultipart;
|
||||
import mcmultipart.multipart.IMultipartContainer;
|
||||
import mcmultipart.multipart.PartSlot;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import refinedstorage.RefinedStorageBlocks;
|
||||
import refinedstorage.api.network.NetworkUtils;
|
||||
|
||||
public abstract class TileMultipartNode extends TileNode implements IMicroblockContainerTile, ISlottedCapabilityProvider {
|
||||
private MicroblockContainer container;
|
||||
@@ -29,7 +34,30 @@ public abstract class TileMultipartNode extends TileNode implements IMicroblockC
|
||||
|
||||
@Override
|
||||
public MicroblockContainer getMicroblockContainer() {
|
||||
return container != null ? container : (container = new MicroblockContainer(this));
|
||||
if (container == null) {
|
||||
container = new MicroblockContainer(this);
|
||||
container.getPartContainer().setListener(new IMultipartContainer.IMultipartContainerListener() {
|
||||
@Override
|
||||
public void onAddPartPre(IMultipart part) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddPartPost(IMultipart part) {
|
||||
onMicroblocksChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovePartPre(IMultipart part) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovePartPost(IMultipart part) {
|
||||
onMicroblocksChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +68,35 @@ public abstract class TileMultipartNode extends TileNode implements IMicroblockC
|
||||
@Override
|
||||
public void onMicroblocksChanged() {
|
||||
markDirty();
|
||||
|
||||
if (network != null) {
|
||||
NetworkUtils.rebuildGraph(network);
|
||||
} else {
|
||||
RefinedStorageBlocks.CABLE.attemptConnect(worldObj, pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasBlockingMicroblock(IBlockAccess world, BlockPos pos, EnumFacing direction) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof TileMultipartNode) {
|
||||
for (IMicroblock microblock : ((TileMultipartNode) tile).getMicroblockContainer().getParts()) {
|
||||
if (microblock instanceof IMicroblock.IFaceMicroblock) {
|
||||
IMicroblock.IFaceMicroblock faceMicroblock = (IMicroblock.IFaceMicroblock) microblock;
|
||||
|
||||
if (faceMicroblock.getFace() == direction && !faceMicroblock.isFaceHollow()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConduct(EnumFacing direction) {
|
||||
return !hasBlockingMicroblock(worldObj, pos, direction) && !hasBlockingMicroblock(worldObj, pos.offset(direction), direction.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package refinedstorage.tile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
@@ -93,7 +94,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConduct() {
|
||||
public boolean canConduct(EnumFacing direction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package refinedstorage.tile;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.tile.config.RedstoneMode;
|
||||
|
||||
@@ -20,7 +21,7 @@ public class TileRelay extends TileNode {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConduct() {
|
||||
public boolean canConduct(EnumFacing direction) {
|
||||
return canUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class TileWirelessTransmitter extends TileNode implements IWirelessTransm
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConduct() {
|
||||
public boolean canConduct(EnumFacing direction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user