Make connectable cable code a bit more efficient with regards to tile entity getting

This commit is contained in:
raoulvdberge
2017-02-26 20:05:00 +01:00
parent 0621708967
commit f9ebe3796f
3 changed files with 27 additions and 18 deletions

View File

@@ -29,8 +29,8 @@ public class NetworkNodeCable extends NetworkNode {
@Override
public boolean canConduct(@Nullable EnumFacing direction) {
if (IntegrationMCMP.isLoaded() && direction != null) {
return RSMCMPAddon.hasConnectionWith(holder.world(), holder.pos(), Collections.singletonList(BlockCable.directionToAABB(direction)))
&& RSMCMPAddon.hasConnectionWith(holder.world(), holder.pos().offset(direction), Collections.singletonList(BlockCable.directionToAABB(direction.getOpposite())));
return RSMCMPAddon.hasConnectionWith(holder.world().getTileEntity(holder.pos()), Collections.singletonList(BlockCable.directionToAABB(direction)))
&& RSMCMPAddon.hasConnectionWith(holder.world().getTileEntity(holder.pos().offset(direction)), Collections.singletonList(BlockCable.directionToAABB(direction.getOpposite())));
}
return true;

View File

@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.integration.mcmp.IntegrationMCMP;
import com.raoulvdberge.refinedstorage.integration.mcmp.RSMCMPAddon;
import com.raoulvdberge.refinedstorage.proxy.CapabilityNetworkNodeProxy;
import com.raoulvdberge.refinedstorage.tile.TileCable;
import com.raoulvdberge.refinedstorage.tile.TileNode;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
@@ -82,23 +83,35 @@ public class BlockCable extends BlockNode {
@Override
@SuppressWarnings("deprecation")
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
return super.getActualState(state, world, pos)
.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));
TileEntity tile = world.getTileEntity(pos);
state = super.getActualState(state, world, pos)
.withProperty(NORTH, hasConnectionWith(world, pos, tile, EnumFacing.NORTH))
.withProperty(EAST, hasConnectionWith(world, pos, tile, EnumFacing.EAST))
.withProperty(SOUTH, hasConnectionWith(world, pos, tile, EnumFacing.SOUTH))
.withProperty(WEST, hasConnectionWith(world, pos, tile, EnumFacing.WEST))
.withProperty(UP, hasConnectionWith(world, pos, tile, EnumFacing.UP))
.withProperty(DOWN, hasConnectionWith(world, pos, tile, EnumFacing.DOWN));
return state;
}
private boolean hasConnectionWith(IBlockAccess world, BlockPos pos, EnumFacing direction) {
private boolean hasConnectionWith(IBlockAccess world, BlockPos pos, TileEntity tile, EnumFacing direction) {
if (!(tile instanceof TileNode)) {
return false;
}
TileEntity otherTile = world.getTileEntity(pos.offset(direction));
EnumFacing otherTileSide = direction.getOpposite();
if (otherTile != null && otherTile.hasCapability(CapabilityNetworkNodeProxy.NETWORK_NODE_PROXY_CAPABILITY, otherTileSide)) {
if (getPlacementType() != null && ((TileNode) tile).getNode().getHolder().getDirection() == direction.getOpposite()) {
return false;
}
if (IntegrationMCMP.isLoaded()) {
return RSMCMPAddon.hasConnectionWith(world, pos, Collections.singletonList(BlockCable.directionToAABB(direction)))
&& RSMCMPAddon.hasConnectionWith(world, pos.offset(direction), Collections.singletonList(BlockCable.directionToAABB(direction.getOpposite())));
return RSMCMPAddon.hasConnectionWith(tile, Collections.singletonList(BlockCable.directionToAABB(direction)))
&& RSMCMPAddon.hasConnectionWith(otherTile, Collections.singletonList(BlockCable.directionToAABB(direction.getOpposite())));
}
return true;

View File

@@ -14,8 +14,6 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
@@ -62,9 +60,7 @@ public class RSMCMPAddon implements IMCMPAddon {
});
}
public static boolean hasConnectionWith(IBlockAccess world, BlockPos pos, List<AxisAlignedBB> aabbs) {
TileEntity tile = world.getTileEntity(pos);
public static boolean hasConnectionWith(TileEntity tile, List<AxisAlignedBB> boxes) {
if (tile != null && tile.hasCapability(MCMPCapabilities.MULTIPART_TILE, null)) {
IMultipartTile multipartTile = tile.getCapability(MCMPCapabilities.MULTIPART_TILE, null);
@@ -72,7 +68,7 @@ public class RSMCMPAddon implements IMCMPAddon {
for (IPartInfo info : ((PartCableTile) multipartTile).getInfo().getContainer().getParts().values()) {
IMultipart multipart = info.getPart();
if (MultipartOcclusionHelper.testBoxIntersection(aabbs, multipart.getOcclusionBoxes(info))) {
if (MultipartOcclusionHelper.testBoxIntersection(boxes, multipart.getOcclusionBoxes(info))) {
return false;
}
}