diff --git a/build.gradle b/build.gradle index b17fd3823..f3920006e 100644 --- a/build.gradle +++ b/build.gradle @@ -108,15 +108,6 @@ dependencies { deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0" } -sourceSets { - main { - java { - exclude 'dan200/computercraft/shared/integration/mcmp' - exclude 'dan200/computercraft/shared/integration/charset' - } - } -} - // Compile tasks javadoc { diff --git a/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java b/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java deleted file mode 100644 index 6fab2ce31..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/charset/BundledCapabilityProvider.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ -package dan200.computercraft.shared.integration.charset; - -import dan200.computercraft.shared.common.TileGeneric; -import net.minecraft.util.Direction; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import pl.asie.charset.api.wires.IBundledEmitter; -import pl.asie.charset.api.wires.IBundledReceiver; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_EMITTER; -import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_RECEIVER; - -final class BundledCapabilityProvider implements ICapabilityProvider -{ - private final TileGeneric tile; - private IBundledReceiver receiver; - private IBundledEmitter[] emitters; - - BundledCapabilityProvider( TileGeneric tile ) - { - this.tile = tile; - } - - @Override - public boolean hasCapability( @Nonnull Capability capability, @Nullable Direction side ) - { - return capability == CAPABILITY_EMITTER || capability == CAPABILITY_RECEIVER; - } - - @Nullable - @Override - public T getCapability( @Nonnull Capability capability, @Nullable Direction side ) - { - if( capability == CAPABILITY_RECEIVER ) - { - IBundledReceiver receiver = this.receiver; - if( receiver == null ) - { - receiver = this.receiver = () -> tile.onNeighbourChange( tile.getPos().offset( side ) ); - } - - return CAPABILITY_RECEIVER.cast( receiver ); - } - else if( capability == CAPABILITY_EMITTER ) - { - IBundledEmitter[] emitters = this.emitters; - if( emitters == null ) emitters = this.emitters = new IBundledEmitter[7]; - - int index = side == null ? 6 : side.getIndex(); - IBundledEmitter emitter = emitters[index]; - if( emitter == null ) - { - if( side == null ) - { - emitter = emitters[index] = () -> { - int flags = 0; - for( Direction facing : Direction.VALUES ) flags |= tile.getBundledRedstoneOutput( facing ); - return toBytes( flags ); - }; - } - else - { - emitter = emitters[index] = () -> toBytes( tile.getBundledRedstoneOutput( side ) ); - } - } - - return CAPABILITY_EMITTER.cast( emitter ); - } - else - { - return null; - } - } - - private static byte[] toBytes( int flag ) - { - byte[] channels = new byte[16]; - for( int i = 0; i < 16; i++ ) channels[i] = (flag & (1 << i)) == 0 ? (byte) 0 : 15; - return channels; - } -} diff --git a/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java b/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java deleted file mode 100644 index a2a857025..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/charset/BundledRedstoneProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ -package dan200.computercraft.shared.integration.charset; - -import dan200.computercraft.api.redstone.IBundledRedstoneProvider; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import javax.annotation.Nonnull; - -import static dan200.computercraft.shared.integration.charset.IntegrationCharset.CAPABILITY_EMITTER; - -public class BundledRedstoneProvider implements IBundledRedstoneProvider -{ - @Override - public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side ) - { - TileEntity tile = world.getTileEntity( pos ); - if( tile == null || !tile.hasCapability( CAPABILITY_EMITTER, side ) ) return -1; - - byte[] signal = tile.getCapability( CAPABILITY_EMITTER, side ).getBundledSignal(); - if( signal == null ) return -1; - - int flag = 0; - for( int i = 0; i < signal.length; i++ ) flag |= signal[i] > 0 ? 1 << i : 0; - return flag; - } -} diff --git a/src/main/java/dan200/computercraft/shared/integration/charset/IntegrationCharset.java b/src/main/java/dan200/computercraft/shared/integration/charset/IntegrationCharset.java deleted file mode 100644 index 32055fc92..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/charset/IntegrationCharset.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ -package dan200.computercraft.shared.integration.charset; - -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.api.ComputerCraftAPI; -import dan200.computercraft.shared.common.TileGeneric; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.CapabilityInject; -import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import pl.asie.charset.api.wires.IBundledEmitter; -import pl.asie.charset.api.wires.IBundledReceiver; - -public final class IntegrationCharset -{ - private static final ResourceLocation CAPABILITY_KEY = new ResourceLocation( ComputerCraft.MOD_ID, "charset" ); - - @CapabilityInject( IBundledEmitter.class ) - static Capability CAPABILITY_EMITTER = null; - - @CapabilityInject( IBundledReceiver.class ) - static Capability CAPABILITY_RECEIVER = null; - - private IntegrationCharset() - { - } - - public static void register() - { - if( CAPABILITY_EMITTER == null || CAPABILITY_RECEIVER == null ) return; - - MinecraftForge.EVENT_BUS.register( IntegrationCharset.class ); - ComputerCraftAPI.registerBundledRedstoneProvider( new BundledRedstoneProvider() ); - } - - @SubscribeEvent - public static void attachGenericCapabilities( AttachCapabilitiesEvent event ) - { - TileEntity tile = event.getObject(); - if( tile instanceof TileGeneric ) - { - event.addCapability( CAPABILITY_KEY, new BundledCapabilityProvider( (TileGeneric) tile ) ); - } - } -} diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java deleted file mode 100644 index f659971fa..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPHooks.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.integration.mcmp; - -import mcmultipart.MCMultiPart; -import mcmultipart.api.item.ItemBlockMultipart; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.fml.common.Loader; - -import javax.annotation.Nonnull; - -public final class MCMPHooks -{ - private MCMPHooks() - { - } - - public static ActionResultType onItemUse( BlockItem itemBlock, PlayerEntity player, World world, @Nonnull BlockPos pos, @Nonnull Hand hand, @Nonnull Direction facing, float hitX, float hitY, float hitZ ) - { - if( !Loader.isModLoaded( MCMultiPart.MODID ) ) return ActionResultType.PASS; - - return ItemBlockMultipart.place( - player, world, pos, hand, facing, hitX, hitY, hitZ, itemBlock, - itemBlock.getBlock()::getStateForPlacement, - MCMPIntegration.multipartMap.get( itemBlock.getBlock() ), - - ( - ItemStack stack, PlayerEntity thisPlayer, World thisWorld, BlockPos thisPos, Direction thisFacing, - float thisX, float thisY, float thisZ, BlockState thisState - ) -> - thisPlayer.canPlayerEdit( thisPos, thisFacing, stack ) && - thisWorld.getBlockState( thisPos ).getBlock().isReplaceable( thisWorld, thisPos ) && - itemBlock.getBlock().canPlaceBlockAt( thisWorld, thisPos ) && - itemBlock.getBlock().canPlaceBlockOnSide( thisWorld, thisPos, thisFacing ) && - itemBlock.placeBlockAt( stack, thisPlayer, thisWorld, thisPos, thisFacing, thisX, thisY, thisZ, thisState ), - ItemBlockMultipart::placePartAt - ); - } -} diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java deleted file mode 100644 index d3031c695..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/MCMPIntegration.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.integration.mcmp; - -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; -import mcmultipart.api.multipart.IMultipart; -import mcmultipart.api.multipart.IMultipartRegistry; -import mcmultipart.api.multipart.IMultipartTile; -import mcmultipart.api.ref.MCMPCapabilities; -import mcmultipart.api.slot.EnumFaceSlot; -import net.minecraft.block.Block; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; - -@MCMPAddon -public class MCMPIntegration implements IMCMPAddon -{ - private static final ResourceLocation CAPABILITY_KEY = new ResourceLocation( ComputerCraft.MOD_ID, "mcmultipart" ); - - static final Map multipartMap = new HashMap<>(); - - private static void register( IMultipartRegistry registry, Block block, IMultipart multipart ) - { - registry.registerPartWrapper( block, multipart ); - multipartMap.put( block, multipart ); - } - - @Override - public void registerParts( IMultipartRegistry registry ) - { - // Setup all parts - register( registry, ComputerCraft.Blocks.peripheral, new PartPeripheral() ); - register( registry, ComputerCraft.Blocks.advancedModem, new PartAdvancedModem() ); - - // Subscribe to capability events - MinecraftForge.EVENT_BUS.register( MCMPIntegration.class ); - - // Register a peripheral provider - ComputerCraftAPI.registerPeripheralProvider( ( world, pos, side ) -> - { - TileEntity tile = world.getTileEntity( pos ); - if( tile == null || !tile.hasCapability( MCMPCapabilities.MULTIPART_CONTAINER, null ) ) return null; - IMultipartContainer container = tile.getCapability( MCMPCapabilities.MULTIPART_CONTAINER, null ); - if( container == null ) return null; - - IMultipartTile multipart = container.getPartTile( EnumFaceSlot.fromFace( side ) ).orElse( null ); - if( multipart == null ) return null; - if( multipart instanceof IPeripheral ) return (IPeripheral) multipart; - if( multipart instanceof IPeripheralTile ) return ((IPeripheralTile) multipart).getPeripheral( side ); - - TileEntity underlying = multipart.getTileEntity(); - if( underlying instanceof IPeripheral ) return (IPeripheral) underlying; - if( underlying instanceof IPeripheralTile ) return ((IPeripheralTile) underlying).getPeripheral( side ); - - return null; - } ); - } - - @SubscribeEvent - public static void attach( AttachCapabilitiesEvent event ) - { - TileEntity tile = event.getObject(); - 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 ) ); - } - } - - private static final class BasicMultipart implements ICapabilityProvider - { - private final TileEntity tile; - private IMultipartTile wrapped; - - private BasicMultipart( TileEntity tile ) - { - this.tile = tile; - } - - @Override - public boolean hasCapability( @Nonnull Capability capability, @Nullable Direction facing ) - { - return capability == MCMPCapabilities.MULTIPART_TILE; - } - - @Nullable - @Override - public T getCapability( @Nonnull Capability capability, @Nullable Direction facing ) - { - if( capability == MCMPCapabilities.MULTIPART_TILE ) - { - IMultipartTile wrapped = this.wrapped; - if( wrapped == null ) wrapped = this.wrapped = IMultipartTile.wrap( tile ); - return MCMPCapabilities.MULTIPART_TILE.cast( wrapped ); - } - - return null; - } - } -} diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java deleted file mode 100644 index b220d33e9..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartAdvancedModem.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.integration.mcmp; - -import dan200.computercraft.ComputerCraft; -import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem; -import mcmultipart.api.multipart.IMultipart; -import mcmultipart.api.slot.EnumFaceSlot; -import mcmultipart.api.slot.IPartSlot; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -public class PartAdvancedModem implements IMultipart -{ - @Override - public IPartSlot getSlotForPlacement( World world, BlockPos pos, BlockState state, Direction facing, float hitX, float hitY, float hitZ, LivingEntity placer ) - { - return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) ); - } - - @Override - public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, BlockState state ) - { - return EnumFaceSlot.fromFace( state.getValue( BlockAdvancedModem.FACING ) ); - } - - @Override - public Block getBlock() - { - return ComputerCraft.Blocks.advancedModem; - } -} diff --git a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java b/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java deleted file mode 100644 index f96572caa..000000000 --- a/src/main/java/dan200/computercraft/shared/integration/mcmp/PartPeripheral.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.integration.mcmp; - -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; -import net.minecraft.block.BlockState; -import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Direction; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -import javax.annotation.Nonnull; - -public class PartPeripheral implements IMultipart -{ - @Override - public IPartSlot getSlotForPlacement( World world, BlockPos pos, BlockState state, Direction facing, float hitX, float hitY, float hitZ, LivingEntity placer ) - { - return getSlot( state ); - } - - @Override - public IPartSlot getSlotFromWorld( IBlockAccess world, BlockPos pos, BlockState state ) - { - return getSlot( state ); - } - - @Nonnull - private static IPartSlot getSlot( BlockState state ) - { - BlockPeripheralVariant type = state.getValue( BlockPeripheral.VARIANT ); - if( type == BlockPeripheralVariant.WirelessModemUpOn || type == BlockPeripheralVariant.WirelessModemUpOff ) - { - return EnumFaceSlot.UP; - } - else if( type == BlockPeripheralVariant.WirelessModemDownOn || type == BlockPeripheralVariant.WirelessModemDownOff ) - { - return EnumFaceSlot.DOWN; - } - else if( type == BlockPeripheralVariant.WirelessModemOff || type == BlockPeripheralVariant.WirelessModemOn ) - { - return EnumFaceSlot.fromFace( state.getValue( BlockPeripheral.FACING ) ); - } - else - { - return EnumCenterSlot.CENTER; - } - } - - @Override - public Block getBlock() - { - return ComputerCraft.Blocks.peripheral; - } -} diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 11490e9ae..4cbbd8083 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -67,8 +67,6 @@ public final class ComputerCraftProxyCommon PlayerCreativeLootCondition.class, PlayerCreativeLootCondition.INSTANCE ) ); - - // if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register(); } private static void registerProviders()