From 01818d4e269a0ba50e9bec39ad740405549671c4 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Mon, 16 Dec 2013 23:52:54 +0000 Subject: [PATCH] Fix up the redstone switching/cover blocking support a bit. --- .../api/transmitters/DynamicNetwork.java | 9 ++++-- .../transmitters/IBlockableConnection.java | 9 ++++++ .../common/multipart/MultipartMekanism.java | 1 + .../common/multipart/PartSidedPipe.java | 10 +++---- .../common/multipart/PartTransmitter.java | 29 ++++++++----------- 5 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 common/mekanism/api/transmitters/IBlockableConnection.java diff --git a/common/mekanism/api/transmitters/DynamicNetwork.java b/common/mekanism/api/transmitters/DynamicNetwork.java index 0282ffa30..558f9f648 100644 --- a/common/mekanism/api/transmitters/DynamicNetwork.java +++ b/common/mekanism/api/transmitters/DynamicNetwork.java @@ -356,10 +356,13 @@ public abstract class DynamicNetwork> implemen if(!iterated.contains(obj) && !toIgnore.contains(obj)) { TileEntity tileEntity = obj.getTileEntity(worldObj); - - if(TransmissionType.checkTransmissionType(tileEntity, transmissionType, location.getTileEntity(worldObj))) + + if(!(tileEntity instanceof IBlockableConnection) || ((IBlockableConnection)tileEntity).canConnectMutual(direction.getOpposite())) { - loopAll(obj); + if(TransmissionType.checkTransmissionType(tileEntity, transmissionType, location.getTileEntity(worldObj))) + { + loopAll(obj); + } } } } diff --git a/common/mekanism/api/transmitters/IBlockableConnection.java b/common/mekanism/api/transmitters/IBlockableConnection.java new file mode 100644 index 000000000..083d97df1 --- /dev/null +++ b/common/mekanism/api/transmitters/IBlockableConnection.java @@ -0,0 +1,9 @@ +package mekanism.api.transmitters; + +import net.minecraftforge.common.ForgeDirection; + +public interface IBlockableConnection +{ + public boolean canConnectMutual(ForgeDirection side); + public boolean canConnect(ForgeDirection side); +} diff --git a/common/mekanism/common/multipart/MultipartMekanism.java b/common/mekanism/common/multipart/MultipartMekanism.java index 2ce8b7762..89452d1fb 100644 --- a/common/mekanism/common/multipart/MultipartMekanism.java +++ b/common/mekanism/common/multipart/MultipartMekanism.java @@ -26,6 +26,7 @@ public class MultipartMekanism implements IPartFactory, IPartConverter MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler"); MultipartGenerator.registerPassThroughInterface("mekanism.common.IConfigurable"); MultipartGenerator.registerPassThroughInterface("mekanism.common.ITileNetwork"); + MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.IBlockableConnection"); } @Override diff --git a/common/mekanism/common/multipart/PartSidedPipe.java b/common/mekanism/common/multipart/PartSidedPipe.java index 61f1843cb..60637858d 100644 --- a/common/mekanism/common/multipart/PartSidedPipe.java +++ b/common/mekanism/common/multipart/PartSidedPipe.java @@ -13,10 +13,7 @@ import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import mekanism.api.Object3D; -import mekanism.api.transmitters.DynamicNetwork; -import mekanism.api.transmitters.ITransmitter; -import mekanism.api.transmitters.TransmissionType; -import mekanism.api.transmitters.TransmitterNetworkRegistry; +import mekanism.api.transmitters.*; import mekanism.client.render.RenderPartTransmitter; import mekanism.common.IConfigurable; import mekanism.common.ITileNetwork; @@ -32,7 +29,7 @@ import net.minecraftforge.common.ForgeDirection; import java.util.*; -public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects, ITileNetwork +public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects, ITileNetwork, IBlockableConnection { public static IndexedCuboid6[] smallSides = new IndexedCuboid6[7]; public static IndexedCuboid6[] largeSides = new IndexedCuboid6[7]; @@ -42,6 +39,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, public byte currentTransmitterConnections = 0x00; public boolean isActive = false; public boolean sendDesc; + public boolean redstonePowered = false; static { @@ -256,7 +254,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart, if(!canConnect(side)) return false; TileEntity tile = Object3D.get(tile()).getFromSide(side).getTileEntity(world()); - return (!(tile instanceof ITransmitter) || ((ITransmitter)tile).canConnect(side.getOpposite())); + return (!(tile instanceof IBlockableConnection) || ((IBlockableConnection)tile).canConnect(side.getOpposite())); } public boolean canConnect(ForgeDirection side) diff --git a/common/mekanism/common/multipart/PartTransmitter.java b/common/mekanism/common/multipart/PartTransmitter.java index 5ddef1123..7fd214fcf 100644 --- a/common/mekanism/common/multipart/PartTransmitter.java +++ b/common/mekanism/common/multipart/PartTransmitter.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import codechicken.multipart.*; import mekanism.api.Object3D; import mekanism.api.transmitters.DynamicNetwork; import mekanism.api.transmitters.ITransmitter; @@ -33,14 +34,6 @@ import codechicken.lib.raytracer.IndexedCuboid6; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Vector3; import codechicken.microblock.IHollowConnect; -import codechicken.multipart.IconHitEffects; -import codechicken.multipart.JIconHitEffects; -import codechicken.multipart.JNormalOcclusion; -import codechicken.multipart.NormalOcclusionTest; -import codechicken.multipart.PartMap; -import codechicken.multipart.TMultiPart; -import codechicken.multipart.TSlottedPart; -import codechicken.multipart.TileMultipart; import com.google.common.io.ByteArrayDataInput; @@ -102,16 +95,18 @@ public abstract class PartTransmitter> extends Pa if(possibleTransmitters != currentTransmitterConnections) { - //TODO @unpairedbracket, I don't think this is necessary; I couldn't tell a difference without it, - //and it results in many extra possible recursive calls on the network - - /*byte or = (byte)(possibleTransmitters | currentTransmitterConnections); - - if(or != possibleTransmitters) + boolean nowPowered = world().isBlockIndirectlyGettingPowered(x(), y(), z()); + + if(nowPowered != redstonePowered) { - ((DynamicNetwork)getTransmitterNetwork()).split((ITransmitter)tile()); - setTransmitterNetwork(null); - }*/ + if(nowPowered) + { + getTransmitterNetwork().split((ITransmitter)tile()); + setTransmitterNetwork(null); + } + tile().notifyPartChange(this); + redstonePowered = nowPowered; + } for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {