Add support for MCMP for all the other remaining cable part blocks
This commit is contained in:
@@ -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<IMultipartTile> multipartTile = ((TileMultipartContainer.Ticking) tile).getPartTile(EnumCenterSlot.CENTER);
|
||||
|
||||
if (multipartTile.isPresent()) {
|
||||
return state.withProperty(DIRECTION, ((TileBase) multipartTile.get().getTileEntity()).getDirection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
|
||||
@@ -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<AxisAlignedBB> getNonUnionizedCollisionBoxes(IBlockState state) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -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<IMultipartTile> multipartTile = ((TileMultipartContainer.Ticking) tile).getPartTile(EnumCenterSlot.CENTER);
|
||||
|
||||
if (multipartTile.isPresent()) {
|
||||
return (TileNode) multipartTile.get().getTileEntity();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasConnectivityState() {
|
||||
|
||||
@@ -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<AxisAlignedBB> getOcclusionBoxes(IPartInfo part) {
|
||||
List<AxisAlignedBB> boxes = new ArrayList<>();
|
||||
|
||||
boxes.add(BlockCable.CORE_AABB);
|
||||
boxes.addAll(block.getNonUnionizedCollisionBoxes(part.getState()));
|
||||
|
||||
return boxes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<TileEntity> 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<TileEntity> e, String id) {
|
||||
e.addCapability(new ResourceLocation("refinedstorage:" + id), new ICapabilityProvider() {
|
||||
private PartCableTile tile;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<TileMultipartContainer> multipartContainer = BlockMultipartContainer.getTile(player.getEntityWorld(), pos);
|
||||
|
||||
if (multipartContainer.isPresent()) {
|
||||
Optional<IPartInfo> 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<AxisAlignedBB> unionized = ((BlockCable) state.getBlock()).getUnionizedCollisionBoxes(state);
|
||||
List<AxisAlignedBB> nonUnionized = ((BlockCable) state.getBlock()).getNonUnionizedCollisionBoxes(state);
|
||||
List<AxisAlignedBB> unionized = cable.getUnionizedCollisionBoxes(state);
|
||||
List<AxisAlignedBB> nonUnionized = cable.getNonUnionizedCollisionBoxes(state);
|
||||
|
||||
e.setCanceled(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user