mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-28 07:36:01 +00:00
Merge pull request #4498 from christofferson/issue-4492
Fix MCMP ClassCastException and usability
This commit is contained in:
commit
9b93a56c95
10 files changed
+482
-43
No files matched your search
@@ -8,6 +8,7 @@ import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.block.property.PropertyColor;
|
||||
import mekanism.common.block.states.BlockStateFacing;
|
||||
import mekanism.common.block.states.BlockStateGlowPanel;
|
||||
import mekanism.common.integration.multipart.MultipartMekanism;
|
||||
import mekanism.common.tile.TileEntityGlowPanel;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MultipartUtils;
|
||||
@@ -72,7 +73,7 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel) MekanismUtils.getTileEntitySafe(world, pos);
|
||||
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
|
||||
return tileEntity != null ? state.withProperty(BlockStateFacing.facingProperty, tileEntity.side) : state;
|
||||
}
|
||||
|
||||
@@ -80,8 +81,8 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel) MekanismUtils.getTileEntitySafe(world, pos);
|
||||
|
||||
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
|
||||
|
||||
if(tileEntity != null)
|
||||
{
|
||||
state = state.withProperty(BlockStateFacing.facingProperty, tileEntity.side);
|
||||
@@ -98,10 +99,10 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbor)
|
||||
{
|
||||
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel)world.getTileEntity(pos);
|
||||
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
|
||||
|
||||
if(!world.isRemote && !canStay(tileEntity))
|
||||
{
|
||||
if(tileEntity != null && !world.isRemote && !canStay(world, pos))
|
||||
{
|
||||
float motion = 0.7F;
|
||||
double motionX = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionY = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
@@ -118,10 +119,10 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor)
|
||||
{
|
||||
TileEntityGlowPanel tileEntity = (TileEntityGlowPanel) MekanismUtils.getTileEntitySafe(world, pos);
|
||||
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
|
||||
|
||||
if(!tileEntity.getWorld().isRemote && !canStay(tileEntity))
|
||||
{
|
||||
if(tileEntity != null && !tileEntity.getWorld().isRemote && !canStay(world, pos))
|
||||
{
|
||||
float motion = 0.7F;
|
||||
double motionX = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionY = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
@@ -138,11 +139,11 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntity tile = MekanismUtils.getTileEntitySafe(world, pos);
|
||||
TileEntityGlowPanel tileEntity = getTileEntityGlowPanel(world, pos);
|
||||
|
||||
if(tile != null && tile instanceof TileEntityGlowPanel)
|
||||
if(tileEntity != null)
|
||||
{
|
||||
return bounds[((TileEntityGlowPanel)tile).side.ordinal()];
|
||||
return bounds[tileEntity.side.ordinal()];
|
||||
}
|
||||
|
||||
return super.getBoundingBox(state, world, pos);
|
||||
@@ -154,10 +155,27 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
return world.isSideSolid(pos.offset(side.getOpposite()), side);
|
||||
}
|
||||
|
||||
public static boolean canStay(TileEntityGlowPanel tileEntity)
|
||||
public static boolean canStay(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
Coord4D adj = new Coord4D(tileEntity.getPos().offset(tileEntity.side), tileEntity.getWorld());
|
||||
return tileEntity.getWorld().isSideSolid(adj.getPos(), tileEntity.side.getOpposite());
|
||||
boolean canStay = false;
|
||||
|
||||
if(Mekanism.hooks.MCMPLoaded)
|
||||
{
|
||||
canStay = MultipartMekanism.hasCenterSlot(world, pos);
|
||||
}
|
||||
|
||||
if(!canStay)
|
||||
{
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if(tileEntity instanceof TileEntityGlowPanel)
|
||||
{
|
||||
TileEntityGlowPanel glowPanel = (TileEntityGlowPanel)tileEntity;
|
||||
Coord4D adj = new Coord4D(glowPanel.getPos().offset(glowPanel.side), glowPanel.getWorld());
|
||||
canStay = glowPanel.getWorld().isSideSolid(adj.getPos(), glowPanel.side.getOpposite());
|
||||
}
|
||||
}
|
||||
|
||||
return canStay;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,4 +256,24 @@ public class BlockGlowPanel extends Block implements ITileEntityProvider
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private static TileEntityGlowPanel getTileEntityGlowPanel(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntity tileEntity = MekanismUtils.getTileEntitySafe(world, pos);
|
||||
TileEntityGlowPanel glowPanel = null;
|
||||
if(tileEntity instanceof TileEntityGlowPanel)
|
||||
{
|
||||
glowPanel = (TileEntityGlowPanel)tileEntity;
|
||||
}
|
||||
else if(Mekanism.hooks.MCMPLoaded)
|
||||
{
|
||||
TileEntity childEntity = MultipartMekanism.unwrapTileEntity(world);
|
||||
if(childEntity instanceof TileEntityGlowPanel)
|
||||
{
|
||||
glowPanel = (TileEntityGlowPanel)childEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return glowPanel;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import mekanism.common.block.property.PropertyConnection;
|
||||
import mekanism.common.block.states.BlockStateTransmitter;
|
||||
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
|
||||
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
|
||||
import mekanism.common.integration.multipart.MultipartMekanism;
|
||||
import mekanism.common.tile.transmitter.TileEntityDiversionTransporter;
|
||||
import mekanism.common.tile.transmitter.TileEntityLogisticalTransporter;
|
||||
import mekanism.common.tile.transmitter.TileEntityMechanicalPipe;
|
||||
@@ -95,11 +96,10 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
|
||||
{
|
||||
TileEntity tile = MekanismUtils.getTileEntitySafe(worldIn, pos);
|
||||
|
||||
if(tile instanceof TileEntitySidedPipe)
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(worldIn, pos);
|
||||
if(tile != null)
|
||||
{
|
||||
state = state.withProperty(BlockStateTransmitter.tierProperty, ((TileEntitySidedPipe)tile).getBaseTier());
|
||||
state = state.withProperty(BlockStateTransmitter.tierProperty, tile.getBaseTier());
|
||||
}
|
||||
|
||||
return state;
|
||||
@@ -129,7 +129,7 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state, IBlockAccess w, BlockPos pos)
|
||||
{
|
||||
TileEntitySidedPipe tile = (TileEntitySidedPipe) MekanismUtils.getTileEntitySafe(w, pos);
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(w, pos);
|
||||
|
||||
if(tile != null)
|
||||
{
|
||||
@@ -147,9 +147,9 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntity tile = MekanismUtils.getTileEntitySafe(world, pos);
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
|
||||
|
||||
if(tile instanceof TileEntitySidedPipe && ((TileEntitySidedPipe)tile).getTransmitterType().getSize() == Size.SMALL)
|
||||
if(tile != null && tile.getTransmitterType().getSize() == Size.SMALL)
|
||||
{
|
||||
return smallSides[6];
|
||||
}
|
||||
@@ -160,7 +160,7 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean b)
|
||||
{
|
||||
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
|
||||
|
||||
if(tile != null)
|
||||
{
|
||||
@@ -176,13 +176,13 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World world, BlockPos pos)
|
||||
{
|
||||
return getDefaultForTile((TileEntitySidedPipe)world.getTileEntity(pos)).offset(pos);
|
||||
return getDefaultForTile(getTileEntitySidedPipe(world, pos)).offset(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayTraceResult collisionRayTrace(IBlockState blockState, World world, BlockPos pos, Vec3d start, Vec3d end)
|
||||
{
|
||||
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
|
||||
|
||||
if(tile == null)
|
||||
{
|
||||
@@ -226,16 +226,20 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
|
||||
{
|
||||
TileEntitySidedPipe tileEntity = (TileEntitySidedPipe)world.getTileEntity(pos);
|
||||
ItemStack itemStack = new ItemStack(MekanismBlocks.Transmitter, 1, tileEntity.getTransmitterType().ordinal());
|
||||
|
||||
if(!itemStack.hasTagCompound())
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
TileEntitySidedPipe tileEntity = getTileEntitySidedPipe(world, pos);
|
||||
if(tileEntity != null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
itemStack = new ItemStack(MekanismBlocks.Transmitter, 1, tileEntity.getTransmitterType().ordinal());
|
||||
|
||||
if(!itemStack.hasTagCompound())
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
ITierItem tierItem = (ITierItem)itemStack.getItem();
|
||||
tierItem.setBaseTier(itemStack, tileEntity.getBaseTier());
|
||||
}
|
||||
|
||||
ITierItem tierItem = (ITierItem)itemStack.getItem();
|
||||
tierItem.setBaseTier(itemStack, tileEntity.getBaseTier());
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
@@ -286,24 +290,33 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
|
||||
{
|
||||
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
|
||||
tile.onAdded();
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
|
||||
if(tile != null)
|
||||
{
|
||||
tile.onAdded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block, BlockPos neighbor)
|
||||
{
|
||||
TileEntitySidedPipe tile = (TileEntitySidedPipe)world.getTileEntity(pos);
|
||||
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
|
||||
tile.onNeighborBlockChange(side);
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
|
||||
if(tile != null)
|
||||
{
|
||||
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
|
||||
tile.onNeighborBlockChange(side);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor)
|
||||
{
|
||||
TileEntitySidedPipe tile = (TileEntitySidedPipe) MekanismUtils.getTileEntitySafe(world, pos);
|
||||
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
|
||||
tile.onNeighborTileChange(side);
|
||||
TileEntitySidedPipe tile = getTileEntitySidedPipe(world, pos);
|
||||
if(tile != null)
|
||||
{
|
||||
EnumFacing side = EnumFacing.getFacingFromVector(neighbor.getX() - pos.getX(), neighbor.getY() - pos.getY(), neighbor.getZ() - pos.getZ());
|
||||
tile.onNeighborTileChange(side);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -424,4 +437,24 @@ public class BlockTransmitter extends Block implements ITileEntityProvider
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TileEntitySidedPipe getTileEntitySidedPipe(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntity tileEntity = MekanismUtils.getTileEntitySafe(world, pos);
|
||||
TileEntitySidedPipe sidedPipe = null;
|
||||
if(tileEntity instanceof TileEntitySidedPipe)
|
||||
{
|
||||
sidedPipe = (TileEntitySidedPipe)tileEntity;
|
||||
}
|
||||
else if(Mekanism.hooks.MCMPLoaded)
|
||||
{
|
||||
TileEntity childEntity = MultipartMekanism.unwrapTileEntity(world);
|
||||
if(childEntity instanceof TileEntitySidedPipe)
|
||||
{
|
||||
sidedPipe = (TileEntitySidedPipe)childEntity;
|
||||
}
|
||||
}
|
||||
|
||||
return sidedPipe;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,23 @@
|
||||
package mekanism.common.integration.multipart;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import mcmultipart.api.container.IPartInfo;
|
||||
import mcmultipart.api.multipart.IMultipart;
|
||||
import mcmultipart.api.slot.EnumFaceSlot;
|
||||
import mcmultipart.api.slot.IPartSlot;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.block.BlockGlowPanel;
|
||||
import mekanism.common.block.states.BlockStateFacing;
|
||||
import mekanism.common.tile.TileEntityGlowPanel;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -13,6 +25,8 @@ import net.minecraft.world.World;
|
||||
|
||||
public class MultipartGlowPanel implements IMultipart
|
||||
{
|
||||
private static Random rand = new Random();
|
||||
|
||||
@Override
|
||||
public IPartSlot getSlotForPlacement(World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY,float hitZ, EntityLivingBase placer)
|
||||
{
|
||||
@@ -24,4 +38,61 @@ public class MultipartGlowPanel implements IMultipart
|
||||
{
|
||||
return EnumFaceSlot.values()[state.getValue(BlockStateFacing.facingProperty).ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartPlacedBy(IPartInfo part, EntityLivingBase placer, ItemStack stack)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
if(tile instanceof TileEntityGlowPanel)
|
||||
{
|
||||
EnumFacing facing = EnumFacing.values()[((EnumFaceSlot)part.getSlot()).ordinal()];
|
||||
EnumColor col = EnumColor.DYES[stack.getItemDamage()];
|
||||
|
||||
TileEntityGlowPanel glowPanel = (TileEntityGlowPanel)tile;
|
||||
glowPanel.setOrientation(facing);
|
||||
glowPanel.setColour(col);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartRemoved(IPartInfo part, IPartInfo otherPart)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
if(tile instanceof TileEntityGlowPanel && !BlockGlowPanel.canStay(part.getPartWorld(), part.getPartPos()))
|
||||
{
|
||||
float motion = 0.7F;
|
||||
double motionX = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionY = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
double motionZ = (rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
|
||||
|
||||
BlockPos pos = part.getPartPos();
|
||||
TileEntityGlowPanel glowPanel = (TileEntityGlowPanel)tile;
|
||||
ItemStack stack = new ItemStack(MekanismBlocks.GlowPanel, 1, glowPanel.colour.getMetaValue());
|
||||
EntityItem entityItem = new EntityItem(glowPanel.getWorld(), pos.getX() + motionX, pos.getY() + motionY, pos.getZ() + motionZ, stack);
|
||||
|
||||
part.getActualWorld().spawnEntity(entityItem);
|
||||
part.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartHarvested(IPartInfo part, EntityPlayer player)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
|
||||
if(tile instanceof TileEntityGlowPanel)
|
||||
{
|
||||
IBlockState partState = part.getState();
|
||||
partState.getBlock().removedByPlayer(partState, part.getPartWorld(),
|
||||
part.getContainer().getPartPos(), player, true);
|
||||
}
|
||||
|
||||
IMultipart.super.onPartHarvested(part, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
return MekanismBlocks.GlowPanel;
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,21 @@ import javax.annotation.Nullable;
|
||||
|
||||
import mcmultipart.api.addon.IMCMPAddon;
|
||||
import mcmultipart.api.addon.MCMPAddon;
|
||||
import mcmultipart.api.container.IMultipartContainer;
|
||||
import mcmultipart.api.container.IPartInfo;
|
||||
import mcmultipart.api.multipart.IMultipart;
|
||||
import mcmultipart.api.multipart.IMultipartRegistry;
|
||||
import mcmultipart.api.multipart.IMultipartTile;
|
||||
import mcmultipart.api.multipart.MultipartCapabilityHelper;
|
||||
import mcmultipart.api.multipart.MultipartOcclusionHelper;
|
||||
import mcmultipart.api.ref.MCMPCapabilities;
|
||||
import mcmultipart.api.slot.EnumCenterSlot;
|
||||
import mcmultipart.api.world.IMultipartBlockAccess;
|
||||
import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.block.BlockTransmitter;
|
||||
import mekanism.common.block.states.BlockStateMachine.MachineType;
|
||||
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.tile.TileEntityGlowPanel;
|
||||
import mekanism.common.tile.transmitter.TileEntityTransmitter;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -29,6 +34,8 @@ 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;
|
||||
@@ -63,6 +70,7 @@ public class MultipartMekanism implements IMCMPAddon
|
||||
registry.registerStackWrapper(Item.getItemFromBlock(MekanismBlocks.Transmitter), s -> true, MekanismBlocks.Transmitter);
|
||||
registry.registerPartWrapper(MekanismBlocks.GlowPanel, new MultipartGlowPanel());
|
||||
registry.registerStackWrapper(Item.getItemFromBlock(MekanismBlocks.GlowPanel), s -> true, MekanismBlocks.GlowPanel);
|
||||
MultipartCapabilityHelper.registerCapabilityJoiner(Capabilities.TILE_NETWORK_CAPABILITY, MultipartTileNetworkJoiner::new);
|
||||
}
|
||||
|
||||
private void register(AttachCapabilitiesEvent<TileEntity> e, String id)
|
||||
@@ -162,4 +170,45 @@ public class MultipartMekanism implements IMCMPAddon
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
static IMultipartContainer getContainer(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
IMultipartContainer container = null;
|
||||
if(world instanceof IMultipartBlockAccess)
|
||||
{
|
||||
container = ((IMultipartBlockAccess) world).getPartInfo().getContainer();
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity possibleContainer = world.getTileEntity(pos);
|
||||
if(possibleContainer instanceof IMultipartContainer)
|
||||
{
|
||||
container = (IMultipartContainer)possibleContainer;
|
||||
}
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public static boolean hasCenterSlot(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
boolean hasCenterSlot = false;
|
||||
IMultipartContainer container = getContainer(world, pos);
|
||||
if(container != null)
|
||||
{
|
||||
hasCenterSlot = container.getPart(EnumCenterSlot.CENTER).isPresent();
|
||||
}
|
||||
|
||||
return hasCenterSlot;
|
||||
}
|
||||
|
||||
public static TileEntity unwrapTileEntity(IBlockAccess world)
|
||||
{
|
||||
TileEntity tile = null;
|
||||
if(world instanceof IMultipartBlockAccess)
|
||||
{
|
||||
tile = ((IMultipartBlockAccess)world).getPartInfo().getTile().getTileEntity();
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package mekanism.common.integration.multipart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mcmultipart.api.container.IMultipartContainer;
|
||||
import mcmultipart.api.multipart.IMultipartTile;
|
||||
import mcmultipart.api.slot.EnumFaceSlot;
|
||||
import mcmultipart.api.slot.IPartSlot;
|
||||
import mcmultipart.api.world.IMultipartBlockAccess;
|
||||
import mekanism.common.base.ITileNetwork;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
/**
|
||||
* Used to route {@link ITileNetwork} packets sent to multipart containers with more than one possible recipient.<br>
|
||||
* <br>
|
||||
* When MCMP is enabled single byte EnumFacing ordinal headers are added to packets sent by glow panels and
|
||||
* transmitters that are then used by this class to route packets to the part attached to the appropriate side.<br>
|
||||
* <br>
|
||||
* In this case, since transmitters do not attach to a side and therefore have no matching EnumFacing the special
|
||||
* value 6 is used to represent the center slot.
|
||||
*/
|
||||
public class MultipartTileNetworkJoiner implements ITileNetwork
|
||||
{
|
||||
private final HashMap<Byte, ITileNetwork> tileSideMap;
|
||||
|
||||
/**
|
||||
* Called by MCMP's multipart container when more than one part implements {@link ITileNetwork}.<br>
|
||||
* <br>
|
||||
* Builds an internal map of part slots to {@link ITileNetwork} implementations in order to route packets.
|
||||
* @param tileList A list of the tile entities that implement {@link ITileNetwork} in the container.
|
||||
*/
|
||||
public MultipartTileNetworkJoiner(List<ITileNetwork> tileList)
|
||||
{
|
||||
tileSideMap = new HashMap<>();
|
||||
IMultipartContainer container = null;
|
||||
|
||||
TileEntity first = (TileEntity)tileList.get(0);
|
||||
IBlockAccess world = first.getWorld();
|
||||
if(world instanceof IMultipartBlockAccess)
|
||||
{
|
||||
container = ((IMultipartBlockAccess)world).getPartInfo().getContainer();
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity worldTile = first.getWorld().getTileEntity(first.getPos());
|
||||
if(worldTile instanceof IMultipartContainer)
|
||||
{
|
||||
container = (IMultipartContainer)worldTile;
|
||||
}
|
||||
}
|
||||
|
||||
if(container != null)
|
||||
{
|
||||
for(IPartSlot slot : container.getParts().keySet())
|
||||
{
|
||||
int tileIndex = tileList.indexOf(container.getPartTile(slot).get().getTileEntity());
|
||||
if(tileIndex >= 0)
|
||||
{
|
||||
byte slotValue = slot instanceof EnumFaceSlot ? (byte)((EnumFaceSlot)slot).ordinal() : 6;
|
||||
tileSideMap.put(slotValue, tileList.get(tileIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(ByteBuf dataStream) throws Exception
|
||||
{
|
||||
while(dataStream.readableBytes() > 0)
|
||||
{
|
||||
byte side = dataStream.readByte();
|
||||
|
||||
ITileNetwork networkTile = tileSideMap.get(side);
|
||||
if(networkTile == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
networkTile.handlePacketData(dataStream);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
|
||||
{
|
||||
ArrayList<Object> childData = new ArrayList<>();
|
||||
for(byte slotValue : tileSideMap.keySet())
|
||||
{
|
||||
tileSideMap.get(slotValue).getNetworkedData(childData);
|
||||
data.addAll(childData);
|
||||
childData.clear();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not an {@link ITileNetwork} joiner is needed and, if so, adds a single byte header
|
||||
* used to route packets inside multipart containers.
|
||||
* @param entity The entity for which <code>getNetworkedData</code> is being called
|
||||
* @param data The network data list
|
||||
* @param facing The side this part is attached to or <code>null</code> for the center slot
|
||||
*/
|
||||
public static void addMultipartHeader(TileEntity entity, ArrayList<Object> data, EnumFacing facing)
|
||||
{
|
||||
int tileNetworkParts = 0;
|
||||
IMultipartContainer container = MultipartMekanism.getContainer(entity.getWorld(), entity.getPos());
|
||||
if(container != null)
|
||||
{
|
||||
for(IPartSlot slot : container.getParts().keySet())
|
||||
{
|
||||
TileEntity part = container.getPartTile(slot)
|
||||
.map(multiPartTile -> multiPartTile.getTileEntity())
|
||||
.orElse(null);
|
||||
|
||||
if(part instanceof ITileNetwork)
|
||||
{
|
||||
tileNetworkParts++;
|
||||
if(tileNetworkParts > 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(tileNetworkParts > 1)
|
||||
{
|
||||
data.add(0, (byte)(facing == null ? 6 : facing.ordinal()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,14 @@ import mcmultipart.api.container.IPartInfo;
|
||||
import mcmultipart.api.multipart.IMultipart;
|
||||
import mcmultipart.api.slot.EnumCenterSlot;
|
||||
import mcmultipart.api.slot.IPartSlot;
|
||||
import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.Tier.BaseTier;
|
||||
import mekanism.common.tile.transmitter.TileEntitySidedPipe;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -27,6 +32,29 @@ public class MultipartTransmitter implements IMultipart
|
||||
return EnumCenterSlot.CENTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded(IPartInfo part)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
|
||||
if(tile instanceof TileEntitySidedPipe)
|
||||
{
|
||||
((TileEntitySidedPipe)tile).onAdded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartAdded(IPartInfo part, IPartInfo otherPart)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
|
||||
if(tile instanceof TileEntitySidedPipe)
|
||||
{
|
||||
tile.validate();
|
||||
((TileEntitySidedPipe)tile).notifyTileChange();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartChanged(IPartInfo part, IPartInfo otherPart)
|
||||
{
|
||||
@@ -37,4 +65,42 @@ public class MultipartTransmitter implements IMultipart
|
||||
((TileEntitySidedPipe)tile).onPartChanged(otherPart.getPart());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartHarvested(IPartInfo part, EntityPlayer player)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
|
||||
if(tile instanceof TileEntitySidedPipe)
|
||||
{
|
||||
IBlockState partState = part.getState();
|
||||
partState.getBlock().removedByPlayer(partState, part.getPartWorld(),
|
||||
part.getContainer().getPartPos(), player, true);
|
||||
}
|
||||
|
||||
IMultipart.super.onPartHarvested(part, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartPlacedBy(IPartInfo part, EntityLivingBase placer, ItemStack stack)
|
||||
{
|
||||
TileEntity tile = part.getTile().getTileEntity();
|
||||
|
||||
if(tile instanceof TileEntitySidedPipe)
|
||||
{
|
||||
BaseTier baseTier = BaseTier.BASIC;
|
||||
if(stack.hasTagCompound())
|
||||
{
|
||||
baseTier = BaseTier.values()[stack.getTagCompound().getInteger("tier")];
|
||||
}
|
||||
|
||||
((TileEntitySidedPipe)tile).setBaseTier(baseTier);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
return MekanismBlocks.Transmitter;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import mekanism.common.base.ITileNetwork;
|
||||
import mekanism.common.block.property.PropertyColor;
|
||||
import mekanism.common.block.states.BlockStateFacing;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.integration.multipart.MultipartTileNetworkJoiner;
|
||||
import mekanism.common.network.PacketDataRequest.DataRequestMessage;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -46,6 +47,11 @@ public class TileEntityGlowPanel extends TileEntity implements ITileNetwork
|
||||
@Override
|
||||
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
|
||||
{
|
||||
if(Mekanism.hooks.MCMPLoaded)
|
||||
{
|
||||
MultipartTileNetworkJoiner.addMultipartHeader(this, data, side);
|
||||
}
|
||||
|
||||
data.add(side.ordinal());
|
||||
data.add(colour.getMetaValue());
|
||||
|
||||
@@ -73,6 +79,12 @@ public class TileEntityGlowPanel extends TileEntity implements ITileNetwork
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag()
|
||||
{
|
||||
return writeToNBT(new NBTTagCompound());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
|
||||
@@ -21,6 +21,7 @@ import mekanism.common.content.transporter.PathfinderCache;
|
||||
import mekanism.common.content.transporter.TransitRequest;
|
||||
import mekanism.common.content.transporter.TransitRequest.TransitResponse;
|
||||
import mekanism.common.content.transporter.TransporterStack;
|
||||
import mekanism.common.integration.multipart.MultipartTileNetworkJoiner;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.transmitters.TransporterImpl;
|
||||
import mekanism.common.transmitters.grid.InventoryNetwork;
|
||||
@@ -271,6 +272,11 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<TileE
|
||||
public ArrayList<Object> getSyncPacket(TransporterStack stack, boolean kill)
|
||||
{
|
||||
ArrayList<Object> data = new ArrayList<Object>();
|
||||
|
||||
if(Mekanism.hooks.MCMPLoaded)
|
||||
{
|
||||
MultipartTileNetworkJoiner.addMultipartHeader(this, data, null);
|
||||
}
|
||||
|
||||
data.add(1);
|
||||
data.add(kill);
|
||||
@@ -344,7 +350,7 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<TileE
|
||||
TransporterUtils.incrementColor(getTransmitter());
|
||||
onPartChanged(null);
|
||||
PathfinderCache.onChanged(new Coord4D(getPos(), getWorld()));
|
||||
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(new Coord4D(getPos(), getWorld()), getNetworkedData(new ArrayList())), new Range4D(new Coord4D(getPos(), getWorld())));
|
||||
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(new Coord4D(getPos(), getWorld()), getNetworkedData(new ArrayList<>())), new Range4D(new Coord4D(getPos(), getWorld())));
|
||||
player.sendMessage(new TextComponentString(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + LangUtils.localize("tooltip.configurator.toggleColor") + ": " + (getTransmitter().getColor() != null ? getTransmitter().getColor().getColoredName() : EnumColor.BLACK + LangUtils.localize("gui.none"))));
|
||||
|
||||
return EnumActionResult.SUCCESS;
|
||||
|
||||
@@ -22,6 +22,7 @@ import mekanism.common.block.states.BlockStateTransmitter.TransmitterType;
|
||||
import mekanism.common.block.states.BlockStateTransmitter.TransmitterType.Size;
|
||||
import mekanism.common.capabilities.Capabilities;
|
||||
import mekanism.common.integration.multipart.MultipartMekanism;
|
||||
import mekanism.common.integration.multipart.MultipartTileNetworkJoiner;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.util.CapabilityUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
@@ -373,6 +374,11 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
|
||||
@Override
|
||||
public ArrayList<Object> getNetworkedData(ArrayList<Object> data)
|
||||
{
|
||||
if(Mekanism.hooks.MCMPLoaded)
|
||||
{
|
||||
MultipartTileNetworkJoiner.addMultipartHeader(this, data, null);
|
||||
}
|
||||
|
||||
data.add(currentTransmitterConnections);
|
||||
data.add(currentAcceptorConnections);
|
||||
|
||||
@@ -412,6 +418,14 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag()
|
||||
{
|
||||
NBTTagCompound nbtTags = super.getUpdateTag();
|
||||
nbtTags.setInteger("tier", getBaseTier().ordinal());
|
||||
return nbtTags;
|
||||
}
|
||||
|
||||
protected void onRefresh() {}
|
||||
|
||||
public void refreshConnections()
|
||||
@@ -481,6 +495,13 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate()
|
||||
{
|
||||
onWorldJoin();
|
||||
super.validate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
@@ -615,7 +636,6 @@ public abstract class TileEntitySidedPipe extends TileEntity implements ITileNet
|
||||
|
||||
for(EnumFacing side : EnumFacing.values())
|
||||
{
|
||||
int ord = side.ordinal();
|
||||
byte connections = getAllCurrentConnections();
|
||||
|
||||
if(connectionMapContainsSide(connections, side))
|
||||
|
||||
@@ -28,6 +28,8 @@ public abstract class TileEntityTransmitter<A, N extends DynamicNetwork<A, N>> e
|
||||
public boolean unloaded = true;
|
||||
|
||||
public boolean dataRequest = false;
|
||||
|
||||
private N lastClientNetwork = null;
|
||||
|
||||
public TileEntityTransmitter()
|
||||
{
|
||||
@@ -50,6 +52,10 @@ public abstract class TileEntityTransmitter<A, N extends DynamicNetwork<A, N>> e
|
||||
{
|
||||
TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
|
||||
}
|
||||
else if(lastClientNetwork != null)
|
||||
{
|
||||
getTransmitter().setTransmitterNetwork(lastClientNetwork);
|
||||
}
|
||||
|
||||
unloaded = false;
|
||||
}
|
||||
@@ -90,6 +96,7 @@ public abstract class TileEntityTransmitter<A, N extends DynamicNetwork<A, N>> e
|
||||
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
||||
}
|
||||
else {
|
||||
lastClientNetwork = getTransmitter().getTransmitterNetwork();
|
||||
getTransmitter().setTransmitterNetwork(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user