mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-15 19:55:42 +00:00
parent
b195cab6a7
commit
48ba247ab4
@ -10,8 +10,10 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheralTile;
|
||||
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.TileAdvancedModem;
|
||||
import dan200.computercraft.shared.peripheral.modem.wireless.TileWirelessModem;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import mcmultipart.api.addon.IMCMPAddon;
|
||||
import mcmultipart.api.addon.MCMPAddon;
|
||||
import mcmultipart.api.container.IMultipartContainer;
|
||||
@ -52,7 +54,7 @@ public class MCMPIntegration implements IMCMPAddon
|
||||
public void registerParts( IMultipartRegistry registry )
|
||||
{
|
||||
// Setup all parts
|
||||
register( registry, ComputerCraft.Blocks.peripheral, new PartNormalModem() );
|
||||
register( registry, ComputerCraft.Blocks.peripheral, new PartPeripheral() );
|
||||
register( registry, ComputerCraft.Blocks.advancedModem, new PartAdvancedModem() );
|
||||
|
||||
// Subscribe to capability events
|
||||
@ -83,8 +85,11 @@ public class MCMPIntegration implements IMCMPAddon
|
||||
public static void attach( AttachCapabilitiesEvent<TileEntity> event )
|
||||
{
|
||||
TileEntity tile = event.getObject();
|
||||
if( tile instanceof TileAdvancedModem || tile instanceof TileWirelessModem )
|
||||
if( tile instanceof TileAdvancedModem || tile instanceof TileWirelessModem
|
||||
|| tile instanceof TilePeripheralBase || tile instanceof TileMonitor )
|
||||
{
|
||||
// We need to attach to modems (obviously), but also any other tile created by BlockPeripheral. Otherwise
|
||||
// IMultipart.convertToMultipartTile will error.
|
||||
event.addCapability( CAPABILITY_KEY, new BasicMultipart( tile ) );
|
||||
}
|
||||
}
|
||||
@ -94,7 +99,10 @@ public class MCMPIntegration implements IMCMPAddon
|
||||
private final TileEntity tile;
|
||||
private IMultipartTile wrapped;
|
||||
|
||||
private BasicMultipart( TileEntity tile ) {this.tile = tile;}
|
||||
private BasicMultipart( TileEntity tile )
|
||||
{
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( @Nonnull Capability<?> capability, @Nullable EnumFacing facing )
|
||||
|
@ -10,6 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
|
||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheralVariant;
|
||||
import mcmultipart.api.multipart.IMultipart;
|
||||
import mcmultipart.api.slot.EnumCenterSlot;
|
||||
import mcmultipart.api.slot.EnumFaceSlot;
|
||||
import mcmultipart.api.slot.IPartSlot;
|
||||
import net.minecraft.block.Block;
|
||||
@ -20,34 +21,41 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PartNormalModem implements IMultipart
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class PartPeripheral implements IMultipart
|
||||
{
|
||||
@Override
|
||||
public IPartSlot getSlotForPlacement( World world, BlockPos pos, IBlockState state, EnumFacing facing, float hitX, float hitY, float hitZ, EntityLivingBase placer )
|
||||
{
|
||||
return EnumFaceSlot.fromFace( getFacing( state ) );
|
||||
return getSlot( state );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, IBlockState state )
|
||||
{
|
||||
return EnumFaceSlot.fromFace( getFacing( state ) );
|
||||
return getSlot( state );
|
||||
}
|
||||
|
||||
private EnumFacing getFacing( IBlockState state )
|
||||
@Nonnull
|
||||
private static IPartSlot getSlot( IBlockState state )
|
||||
{
|
||||
BlockPeripheralVariant type = state.getValue( BlockPeripheral.VARIANT );
|
||||
if( type == BlockPeripheralVariant.WirelessModemUpOn || type == BlockPeripheralVariant.WirelessModemUpOff )
|
||||
{
|
||||
return EnumFacing.UP;
|
||||
return EnumFaceSlot.UP;
|
||||
}
|
||||
else if( type == BlockPeripheralVariant.WirelessModemDownOn || type == BlockPeripheralVariant.WirelessModemDownOff )
|
||||
{
|
||||
return EnumFacing.UP;
|
||||
return EnumFaceSlot.DOWN;
|
||||
}
|
||||
else if( type == BlockPeripheralVariant.WirelessModemOff || type == BlockPeripheralVariant.WirelessModemOn )
|
||||
{
|
||||
return EnumFaceSlot.fromFace( state.getValue( BlockPeripheral.FACING ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return state.getValue( BlockPeripheral.FACING );
|
||||
return EnumCenterSlot.CENTER;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user