fix covers not preventing netrwork connections

This commit is contained in:
Darkere
2021-10-31 12:55:44 +01:00
parent 4cf7062d81
commit 2a27275ba3
5 changed files with 28 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ package com.refinedmods.refinedstorage.api.network.node;
import com.refinedmods.refinedstorage.api.network.INetwork;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -91,6 +92,15 @@ public interface INetworkNode {
*/
ResourceLocation getId();
/**
* @param direction the direction
* @return whether a network signal can be conducted in the given direction.
*/
default boolean canConduct(Direction direction) {
return true;
}
/**
* @param owner the owner
*/

View File

@@ -3,8 +3,9 @@ package com.refinedmods.refinedstorage.apiimpl.network.node;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.api.network.node.ICoverable;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.refinedmods.refinedstorage.util.WorldUtils;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverType;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -19,6 +20,11 @@ public class CableNetworkNode extends NetworkNode implements ICoverable {
this.coverManager = new CoverManager(this);
}
@Override
public boolean canConduct(Direction direction) {
return !coverManager.hasCover(direction) || coverManager.getCover(direction).getType() == CoverType.HOLLOW;
}
@Override
public int getEnergyUsage() {
return RS.SERVER_CONFIG.getCable().getUsage();

View File

@@ -8,6 +8,7 @@ import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.block.BaseBlock;
import com.refinedmods.refinedstorage.block.NetworkNodeBlock;
import com.refinedmods.refinedstorage.tile.config.RedstoneMode;
import com.refinedmods.refinedstorage.util.NetworkUtils;
import net.minecraft.block.BlockState;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -224,18 +225,20 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor {
return world;
}
/**
* @param direction the direction
* @return whether a network signal can be conducted in the given direction.
*/
protected boolean canConduct(Direction direction) {
@Override
public boolean canConduct(Direction direction) {
return true;
}
@Override
public void visit(Operator operator) {
for (Direction facing : Direction.values()) {
if (canConduct(facing)) {
INetworkNode oppositeNode = NetworkUtils.getNodeFromTile(world.getTileEntity(pos.offset(facing)));
if (oppositeNode == null) {
continue;
}
if (canConduct(facing) && oppositeNode.canConduct(facing.getOpposite())) {
operator.apply(world, pos.offset(facing), facing.getOpposite());
}
}

View File

@@ -37,7 +37,7 @@ public class RelayNetworkNode extends NetworkNode {
}
@Override
protected boolean canConduct(Direction direction) {
public boolean canConduct(Direction direction) {
return canUpdate();
}

View File

@@ -75,7 +75,7 @@ public class WirelessTransmitterNetworkNode extends NetworkNode implements IWire
}
@Override
protected boolean canConduct(Direction direction) {
public boolean canConduct(Direction direction) {
return Direction.DOWN.equals(direction);
}