Covers block cable connections.
This commit is contained in:
@@ -3,6 +3,7 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
@@ -36,6 +37,11 @@ public class NetworkNodeCable extends NetworkNode implements ICoverable {
|
||||
return coverManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConduct(@Nullable EnumFacing direction) {
|
||||
return coverManager.canConduct(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound write(NBTTagCompound tag) {
|
||||
super.write(tag);
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.raoulvdberge.refinedstorage.apiimpl.network.node.cover;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.ICoverable;
|
||||
import com.raoulvdberge.refinedstorage.item.ItemCover;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -30,17 +32,38 @@ public class CoverManager {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public boolean canConduct(EnumFacing direction) {
|
||||
if (hasCover(direction)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
INetworkNode neighbor = API.instance().getNetworkNodeManager(node.getWorld()).getNode(node.getPos().offset(direction));
|
||||
if (neighbor instanceof ICoverable && ((ICoverable) neighbor).getCoverManager().hasCover(direction.getOpposite())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getCover(EnumFacing facing) {
|
||||
return covers.get(facing);
|
||||
}
|
||||
|
||||
public boolean setCover(EnumFacing cover, ItemStack stack) {
|
||||
if (isValidCover(stack) && !covers.containsKey(cover)) {
|
||||
covers.put(cover, stack);
|
||||
public boolean hasCover(EnumFacing facing) {
|
||||
return covers.containsKey(facing);
|
||||
}
|
||||
|
||||
public boolean setCover(EnumFacing facing, ItemStack stack) {
|
||||
if (isValidCover(stack) && !hasCover(facing)) {
|
||||
covers.put(facing, stack);
|
||||
|
||||
node.markDirty();
|
||||
|
||||
if (node.getNetwork() != null) {
|
||||
node.getNetwork().getNodeGraph().rebuild();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -93,6 +116,7 @@ public class CoverManager {
|
||||
return handler;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean isValidCover(ItemStack item) {
|
||||
if (item.isEmpty()) {
|
||||
return false;
|
||||
@@ -129,6 +153,7 @@ public class CoverManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SuppressWarnings("deprecation")
|
||||
public static IBlockState getBlockState(@Nullable ItemStack item) {
|
||||
Block block = getBlock(item);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.raoulvdberge.refinedstorage.block;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.ICoverable;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
|
||||
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
||||
@@ -133,8 +134,22 @@ public class BlockCable extends BlockNode {
|
||||
return false;
|
||||
}
|
||||
|
||||
INetworkNode node = ((TileNode) tile).getNode();
|
||||
|
||||
if (node instanceof ICoverable && ((ICoverable) node).getCoverManager().hasCover(direction)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity otherTile = world.getTileEntity(pos.offset(direction));
|
||||
|
||||
if (otherTile instanceof TileNode) {
|
||||
INetworkNode otherNode = ((TileNode) otherTile).getNode();
|
||||
|
||||
if (otherNode instanceof ICoverable && ((ICoverable) otherNode).getCoverManager().hasCover(direction.getOpposite())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (otherTile != null && otherTile.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, direction.getOpposite())) {
|
||||
// Prevent the block adding connections in itself
|
||||
// For example: importer cable connection on the importer face
|
||||
@@ -198,13 +213,13 @@ public class BlockCable extends BlockNode {
|
||||
if (tile instanceof TileNode && ((TileNode) tile).getNode() instanceof ICoverable) {
|
||||
CoverManager coverManager = ((ICoverable) ((TileNode) tile).getNode()).getCoverManager();
|
||||
|
||||
boolean hasUp = coverManager.getCover(EnumFacing.UP) != null;
|
||||
boolean hasDown = coverManager.getCover(EnumFacing.DOWN) != null;
|
||||
boolean hasUp = coverManager.hasCover(EnumFacing.UP);
|
||||
boolean hasDown = coverManager.hasCover(EnumFacing.DOWN);
|
||||
|
||||
boolean hasEast = coverManager.getCover(EnumFacing.EAST) != null;
|
||||
boolean hasWest = coverManager.getCover(EnumFacing.WEST) != null;
|
||||
boolean hasEast = coverManager.hasCover(EnumFacing.EAST);
|
||||
boolean hasWest = coverManager.hasCover(EnumFacing.WEST);
|
||||
|
||||
if (coverManager.getCover(EnumFacing.NORTH) != null) {
|
||||
if (coverManager.hasCover(EnumFacing.NORTH)) {
|
||||
boxes.add(RenderUtils.getBounds(
|
||||
hasWest ? 2 : 0, hasDown ? 2 : 0, 0,
|
||||
hasEast ? 14 : 16, hasUp ? 14 : 16, 2
|
||||
@@ -222,7 +237,7 @@ public class BlockCable extends BlockNode {
|
||||
boxes.add(HOLDER_EAST_AABB);
|
||||
}
|
||||
|
||||
if (coverManager.getCover(EnumFacing.SOUTH) != null) {
|
||||
if (coverManager.hasCover(EnumFacing.SOUTH)) {
|
||||
boxes.add(RenderUtils.getBounds(
|
||||
hasEast ? 14 : 16, hasDown ? 2 : 0, 16,
|
||||
hasWest ? 2 : 0, hasUp ? 14 : 16, 14
|
||||
|
||||
Reference in New Issue
Block a user