diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockBase.java b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockBase.java index 144c5083e..4c48e10fb 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockBase.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockBase.java @@ -5,9 +5,13 @@ import com.raoulvdberge.refinedstorage.RSUtils; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy; import com.raoulvdberge.refinedstorage.api.network.security.Permission; +import com.raoulvdberge.refinedstorage.integration.mcmp.IntegrationMCMP; import com.raoulvdberge.refinedstorage.item.ItemBlockBase; import com.raoulvdberge.refinedstorage.proxy.CapabilityNetworkNodeProxy; import com.raoulvdberge.refinedstorage.tile.TileBase; +import mcmultipart.api.multipart.IMultipartTile; +import mcmultipart.api.slot.EnumCenterSlot; +import mcmultipart.block.TileMultipartContainer; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyDirection; @@ -25,6 +29,8 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.items.IItemHandler; +import java.util.Optional; + public abstract class BlockBase extends Block { public static final PropertyDirection DIRECTION = PropertyDirection.create("direction"); @@ -79,7 +85,17 @@ public abstract class BlockBase extends Block { @SuppressWarnings("deprecation") public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { if (getPlacementType() != null) { - return state.withProperty(DIRECTION, ((TileBase) world.getTileEntity(pos)).getDirection()); + TileEntity tile = world.getTileEntity(pos); + + if (tile instanceof TileBase) { + return state.withProperty(DIRECTION, ((TileBase) tile).getDirection()); + } else if (IntegrationMCMP.isLoaded() && tile instanceof TileMultipartContainer.Ticking) { + Optional multipartTile = ((TileMultipartContainer.Ticking) tile).getPartTile(EnumCenterSlot.CENTER); + + if (multipartTile.isPresent()) { + return state.withProperty(DIRECTION, ((TileBase) multipartTile.get().getTileEntity()).getDirection()); + } + } } return state; diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockCable.java b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockCable.java index 65f04c6f2..2f410a039 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockCable.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockCable.java @@ -30,13 +30,13 @@ public class BlockCable extends BlockNode { return new AxisAlignedBB((float) fromX / 16F, (float) fromY / 16F, (float) fromZ / 16F, (float) toX / 16F, (float) toY / 16F, (float) toZ / 16F); } - protected static AxisAlignedBB CORE_AABB = createAABB(6, 6, 6, 10, 10, 10); - protected static AxisAlignedBB NORTH_AABB = createAABB(6, 6, 0, 10, 10, 6); - protected static AxisAlignedBB EAST_AABB = createAABB(10, 6, 6, 16, 10, 10); - protected static AxisAlignedBB SOUTH_AABB = createAABB(6, 6, 10, 10, 10, 16); - protected static AxisAlignedBB WEST_AABB = createAABB(0, 6, 6, 6, 10, 10); - protected static AxisAlignedBB UP_AABB = createAABB(6, 10, 6, 10, 16, 10); - protected static AxisAlignedBB DOWN_AABB = createAABB(6, 0, 6, 10, 6, 10); + public static final AxisAlignedBB CORE_AABB = createAABB(6, 6, 6, 10, 10, 10); + protected static final AxisAlignedBB NORTH_AABB = createAABB(6, 6, 0, 10, 10, 6); + protected static final AxisAlignedBB EAST_AABB = createAABB(10, 6, 6, 16, 10, 10); + protected static final AxisAlignedBB SOUTH_AABB = createAABB(6, 6, 10, 10, 10, 16); + protected static final AxisAlignedBB WEST_AABB = createAABB(0, 6, 6, 6, 10, 10); + protected static final AxisAlignedBB UP_AABB = createAABB(6, 10, 6, 10, 16, 10); + protected static final AxisAlignedBB DOWN_AABB = createAABB(6, 0, 6, 10, 6, 10); protected static final PropertyBool NORTH = PropertyBool.create("north"); protected static final PropertyBool EAST = PropertyBool.create("east"); @@ -83,7 +83,7 @@ public class BlockCable extends BlockNode { @Override @SuppressWarnings("deprecation") public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { - TileEntity tile = world.getTileEntity(pos); + TileNode tile = getNode(world, pos); state = super.getActualState(state, world, pos) .withProperty(NORTH, hasConnectionWith(world, pos, tile, EnumFacing.NORTH)) @@ -96,6 +96,19 @@ public class BlockCable extends BlockNode { return state; } + // This is used for rendering the box outlines in the client proxy. + // We use this because MCMP wraps the block in a MCMP wrapper block, creating issues where + // it cannot assign properties to the MCMP blockstate. Here, we make sure that it uses our block state. + private IBlockState stateForRendering; + + public IBlockState getActualStateForRendering(IBlockAccess world, BlockPos pos) { + if (stateForRendering == null) { + stateForRendering = createBlockState().getBaseState(); + } + + return getActualState(stateForRendering, world, pos); + } + private boolean hasConnectionWith(IBlockAccess world, BlockPos pos, TileEntity tile, EnumFacing direction) { if (!(tile instanceof TileNode)) { return false; @@ -186,11 +199,6 @@ public class BlockCable extends BlockNode { return boxes; } - @Override - public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { - return CORE_AABB; - } - public List getNonUnionizedCollisionBoxes(IBlockState state) { return Collections.emptyList(); } diff --git a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockNode.java b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockNode.java index 6fd835134..82c7eec56 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/block/BlockNode.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/block/BlockNode.java @@ -3,7 +3,11 @@ package com.raoulvdberge.refinedstorage.block; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode; import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager; import com.raoulvdberge.refinedstorage.apiimpl.API; +import com.raoulvdberge.refinedstorage.integration.mcmp.IntegrationMCMP; import com.raoulvdberge.refinedstorage.tile.TileNode; +import mcmultipart.api.multipart.IMultipartTile; +import mcmultipart.api.slot.EnumCenterSlot; +import mcmultipart.block.TileMultipartContainer; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; @@ -15,6 +19,8 @@ import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import java.util.Optional; + public abstract class BlockNode extends BlockBase { public static final String NBT_REFINED_STORAGE_DATA = "RefinedStorageData"; @@ -97,11 +103,33 @@ public abstract class BlockNode extends BlockBase { @Override public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) { + state = super.getActualState(state, world, pos); + if (hasConnectivityState()) { - return super.getActualState(state, world, pos).withProperty(CONNECTED, ((TileNode) world.getTileEntity(pos)).getNode().isActive()); + TileNode tile = getNode(world, pos); + + if (tile != null) { + return state.withProperty(CONNECTED, tile.getNode().isActive()); + } } - return super.getActualState(state, world, pos); + return state; + } + + public static TileNode getNode(IBlockAccess world, BlockPos pos) { + TileEntity tile = world.getTileEntity(pos); + + if (tile instanceof TileNode) { + return (TileNode) tile; + } else if (IntegrationMCMP.isLoaded() && tile instanceof TileMultipartContainer.Ticking) { + Optional multipartTile = ((TileMultipartContainer.Ticking) tile).getPartTile(EnumCenterSlot.CENTER); + + if (multipartTile.isPresent()) { + return (TileNode) multipartTile.get().getTileEntity(); + } + } + + return null; } public boolean hasConnectivityState() { diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/PartCable.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/PartCable.java index 236aa08a7..0b8faa58b 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/PartCable.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/PartCable.java @@ -1,7 +1,7 @@ package com.raoulvdberge.refinedstorage.integration.mcmp; -import com.raoulvdberge.refinedstorage.RSBlocks; import com.raoulvdberge.refinedstorage.apiimpl.API; +import com.raoulvdberge.refinedstorage.block.BlockCable; import mcmultipart.api.container.IPartInfo; import mcmultipart.api.multipart.IMultipart; import mcmultipart.api.slot.EnumCenterSlot; @@ -10,11 +10,21 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; 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 java.util.ArrayList; +import java.util.List; + public class PartCable implements IMultipart { + private BlockCable block; + + public PartCable(BlockCable block) { + this.block = block; + } + @Override public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer) { return EnumCenterSlot.CENTER; @@ -27,7 +37,17 @@ public class PartCable implements IMultipart { @Override public Block getBlock() { - return RSBlocks.CABLE; + return block; + } + + @Override + public List getOcclusionBoxes(IPartInfo part) { + List boxes = new ArrayList<>(); + + boxes.add(BlockCable.CORE_AABB); + boxes.addAll(block.getNonUnionizedCollisionBoxes(part.getState())); + + return boxes; } @Override diff --git a/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/RSMCMPAddon.java b/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/RSMCMPAddon.java index d153107df..d472464ca 100644 --- a/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/RSMCMPAddon.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/integration/mcmp/RSMCMPAddon.java @@ -1,6 +1,7 @@ package com.raoulvdberge.refinedstorage.integration.mcmp; import com.raoulvdberge.refinedstorage.RSBlocks; +import com.raoulvdberge.refinedstorage.block.BlockCable; import mcmultipart.api.addon.IMCMPAddon; import mcmultipart.api.addon.MCMPAddon; import mcmultipart.api.container.IPartInfo; @@ -30,13 +31,35 @@ public class RSMCMPAddon implements IMCMPAddon { public void registerParts(IMultipartRegistry registry) { MinecraftForge.EVENT_BUS.register(this); - registry.registerPartWrapper(RSBlocks.CABLE, new PartCable()); - registry.registerStackWrapper(Item.getItemFromBlock(RSBlocks.CABLE), s -> true, RSBlocks.CABLE); + register(registry, RSBlocks.CABLE); + register(registry, RSBlocks.CONSTRUCTOR); + register(registry, RSBlocks.DESTRUCTOR); + register(registry, RSBlocks.IMPORTER); + register(registry, RSBlocks.EXPORTER); + register(registry, RSBlocks.EXTERNAL_STORAGE); + register(registry, RSBlocks.READER); + register(registry, RSBlocks.WRITER); + } + + private void register(IMultipartRegistry registry, BlockCable block) { + registry.registerPartWrapper(block, new PartCable(block)); + registry.registerStackWrapper(Item.getItemFromBlock(block), s -> true, block); } @SubscribeEvent public void onAttachCapability(AttachCapabilitiesEvent e) { - e.addCapability(new ResourceLocation("refinedstorage:cable"), new ICapabilityProvider() { + register(e, "cable"); + register(e, "constructor"); + register(e, "destructor"); + register(e, "importer"); + register(e, "exporter"); + register(e, "external_storage"); + register(e, "reader"); + register(e, "writer"); + } + + private void register(AttachCapabilitiesEvent e, String id) { + e.addCapability(new ResourceLocation("refinedstorage:" + id), new ICapabilityProvider() { private PartCableTile tile; @Override diff --git a/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java b/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java index 5c2e3e884..12f434efe 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/proxy/ProxyClient.java @@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.RSUtils; import com.raoulvdberge.refinedstorage.block.*; import com.raoulvdberge.refinedstorage.gui.GuiCraftingPreview; import com.raoulvdberge.refinedstorage.gui.grid.GuiCraftingStart; +import com.raoulvdberge.refinedstorage.integration.mcmp.IntegrationMCMP; import com.raoulvdberge.refinedstorage.item.*; import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse; import com.raoulvdberge.refinedstorage.render.BakedModelPattern; @@ -15,6 +16,11 @@ import com.raoulvdberge.refinedstorage.render.ModelDiskManipulator; import com.raoulvdberge.refinedstorage.render.TileEntitySpecialRendererStorageMonitor; import com.raoulvdberge.refinedstorage.tile.TileController; import com.raoulvdberge.refinedstorage.tile.TileStorageMonitor; +import mcmultipart.api.container.IPartInfo; +import mcmultipart.api.slot.EnumCenterSlot; +import mcmultipart.block.BlockMultipartContainer; +import mcmultipart.block.TileMultipartContainer; +import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -45,6 +51,7 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.util.List; +import java.util.Optional; public class ProxyClient extends ProxyCommon { @Override @@ -293,18 +300,38 @@ public class ProxyClient extends ProxyCommon { IBlockState state = player.getEntityWorld().getBlockState(pos); - if (!(state.getBlock() instanceof BlockCable)) { + BlockCable cable = null; + + if (state.getBlock() instanceof BlockCable) { + cable = (BlockCable) state.getBlock(); + } else if (IntegrationMCMP.isLoaded() && state.getBlock() instanceof BlockMultipartContainer) { + Optional multipartContainer = BlockMultipartContainer.getTile(player.getEntityWorld(), pos); + + if (multipartContainer.isPresent()) { + Optional info = multipartContainer.get().get(EnumCenterSlot.CENTER); + + if (info.isPresent()) { + Block block = info.get().getPart().getBlock(); + + if (block instanceof BlockCable) { + cable = (BlockCable) block; + } + } + } + } + + if (cable == null) { return; } - state = ((BlockCable) state.getBlock()).getActualState(state, player.getEntityWorld(), pos); + state = cable.getActualStateForRendering(player.getEntityWorld(), pos); - if (((BlockCable) state.getBlock()).collisionRayTrace(state, player.getEntityWorld(), pos, RSUtils.getStart(player), RSUtils.getEnd(player)) == null) { + if (cable.collisionRayTrace(state, player.getEntityWorld(), pos, RSUtils.getStart(player), RSUtils.getEnd(player)) == null) { return; } - List unionized = ((BlockCable) state.getBlock()).getUnionizedCollisionBoxes(state); - List nonUnionized = ((BlockCable) state.getBlock()).getNonUnionizedCollisionBoxes(state); + List unionized = cable.getUnionizedCollisionBoxes(state); + List nonUnionized = cable.getNonUnionizedCollisionBoxes(state); e.setCanceled(true);