Search in sources :

Example 1 with Lockable

use of pl.asie.charset.api.locks.Lockable in project Charset by CharsetMC.

the class CarryHandler method canPickUp.

private boolean canPickUp(World world, BlockPos pos, IBlockState block) {
    if (player instanceof EntityPlayer && ((EntityPlayer) player).isCreative()) {
        return true;
    }
    // Check TileEntityLockable
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileEntityLockable && ((TileEntityLockable) tile).isLocked()) {
        return false;
    }
    // Check IMultiblockStructure
    IMultiblockStructure structure = CapabilityHelper.get(world, pos, Capabilities.MULTIBLOCK_STRUCTURE, null, true, true, false);
    if (structure != null && !structure.isSeparable()) {
        int count = 0;
        Iterator<BlockPos> it = structure.iterator();
        while (it.hasNext()) {
            if (++count >= 2)
                return false;
        }
    }
    // Check IMovable
    IMovable movable = CapabilityHelper.get(world, pos, Capabilities.MOVABLE, null, true, true, false);
    if (movable != null && !movable.canMoveFrom()) {
        return false;
    }
    // Check Lock
    Lockable lockable = CapabilityHelper.get(world, pos, Capabilities.LOCKABLE, null, true, true, false);
    if (lockable != null && lockable.hasLock()) {
        return false;
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLockable(net.minecraft.tileentity.TileEntityLockable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) TileEntityLockable(net.minecraft.tileentity.TileEntityLockable) Lockable(pl.asie.charset.api.locks.Lockable) IMovable(pl.asie.charset.api.lib.IMovable) IMultiblockStructure(pl.asie.charset.api.lib.IMultiblockStructure)

Example 2 with Lockable

use of pl.asie.charset.api.locks.Lockable in project Charset by CharsetMC.

the class Capabilities method preInit.

public static void preInit() {
    CapabilityManager.INSTANCE.register(IAudioSource.class, DummyCapabilityStorage.get(), DefaultAudioSource::new);
    CapabilityManager.INSTANCE.register(IAudioReceiver.class, DummyCapabilityStorage.get(), DefaultAudioReceiver::new);
    CapabilityManager.INSTANCE.register(IAxisRotatable.class, DummyCapabilityStorage.get(), DefaultAxisRotatable::new);
    CapabilityManager.INSTANCE.register(IDebuggable.class, DummyCapabilityStorage.get(), DefaultDebuggable::new);
    CapabilityManager.INSTANCE.register(IMovable.class, DummyCapabilityStorage.get(), DefaultMovable::new);
    CapabilityManager.INSTANCE.register(IItemInsertionHandler.class, DummyCapabilityStorage.get(), DefaultItemInsertionHandler::new);
    CapabilityManager.INSTANCE.register(IPipeView.class, DummyCapabilityStorage.get(), DefaultPipeView::new);
    CapabilityManager.INSTANCE.register(IBundledEmitter.class, new DefaultBundledEmitterStorage(), DefaultBundledEmitter::new);
    CapabilityManager.INSTANCE.register(IRedstoneEmitter.class, new DefaultRedstoneEmitterStorage(), DefaultRedstoneEmitter::new);
    CapabilityManager.INSTANCE.register(IBundledReceiver.class, DummyCapabilityStorage.get(), DummyRedstoneReceiver::new);
    CapabilityManager.INSTANCE.register(IRedstoneReceiver.class, DummyCapabilityStorage.get(), DummyRedstoneReceiver::new);
    CapabilityManager.INSTANCE.register(IBarrel.class, DummyCapabilityStorage.get(), DummyBarrel::new);
    CapabilityManager.INSTANCE.register(Lockable.class, LOCKABLE_STORAGE, Lockable::new);
    CapabilityManager.INSTANCE.register(IMultiblockStructure.class, DummyCapabilityStorage.get(), DefaultMultiblockStructure::new);
    CapabilityManager.INSTANCE.register(ILaserReceiver.class, DummyCapabilityStorage.get(), DummyLaserReceiver::new);
    CapabilityManager.INSTANCE.register(CustomCarryHandler.Provider.class, DummyCapabilityStorage.get(), () -> handler -> new CustomCarryHandler(handler));
    MinecraftForge.EVENT_BUS.register(new Capabilities());
    multiblockStructureFactory = new CapabilityProviderFactory<>(Capabilities.MULTIBLOCK_STRUCTURE, DummyCapabilityStorage.get());
}
Also used : DefaultPipeView(pl.asie.charset.lib.capability.pipe.DefaultPipeView) Lockable(pl.asie.charset.api.locks.Lockable) DefaultAudioReceiver(pl.asie.charset.lib.capability.audio.DefaultAudioReceiver) DefaultItemInsertionHandler(pl.asie.charset.lib.capability.inventory.DefaultItemInsertionHandler) DefaultAudioSource(pl.asie.charset.lib.capability.audio.DefaultAudioSource) DummyLaserReceiver(pl.asie.charset.lib.capability.laser.DummyLaserReceiver) CustomCarryHandler(pl.asie.charset.api.carry.CustomCarryHandler) DummyBarrel(pl.asie.charset.lib.capability.storage.DummyBarrel)

Example 3 with Lockable

use of pl.asie.charset.api.locks.Lockable in project Charset by CharsetMC.

the class EntityLock method drop.

public void drop() {
    Lockable lock = getAttachedLock();
    if (lock != null) {
        lock.removeLock(this);
    }
    this.entityDropItem(createItemStack(CharsetStorageLocks.lockItem), 0.0F);
    this.setDead();
}
Also used : Lockable(pl.asie.charset.api.locks.Lockable)

Example 4 with Lockable

use of pl.asie.charset.api.locks.Lockable in project Charset by CharsetMC.

the class LockEventHandler method onLeftClick.

@SubscribeEvent(priority = EventPriority.HIGH)
public void onLeftClick(PlayerInteractEvent.LeftClickBlock event) {
    TileEntity tile = event.getWorld().getTileEntity(event.getPos());
    Lockable lockable = getLock(tile);
    if (lockable != null && !unlockOrRaiseError(event.getEntityPlayer(), tile, lockable)) {
        event.setUseBlock(Event.Result.DENY);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLockable(net.minecraft.tileentity.TileEntityLockable) Lockable(pl.asie.charset.api.locks.Lockable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with Lockable

use of pl.asie.charset.api.locks.Lockable in project Charset by CharsetMC.

the class LockEventHandler method onRightClick.

@SubscribeEvent(priority = EventPriority.HIGH)
public void onRightClick(PlayerInteractEvent.RightClickBlock event) {
    TileEntity tile = event.getWorld().getTileEntity(event.getPos());
    Lockable lockable = getLock(tile);
    if (lockable != null && !unlockOrRaiseError(event.getEntityPlayer(), tile, lockable)) {
        event.setUseBlock(Event.Result.DENY);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLockable(net.minecraft.tileentity.TileEntityLockable) Lockable(pl.asie.charset.api.locks.Lockable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Lockable (pl.asie.charset.api.locks.Lockable)9 TileEntity (net.minecraft.tileentity.TileEntity)6 TileEntityLockable (net.minecraft.tileentity.TileEntityLockable)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 BlockPos (net.minecraft.util.math.BlockPos)3 IBlockState (net.minecraft.block.state.IBlockState)2 IMultiblockStructure (pl.asie.charset.api.lib.IMultiblockStructure)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 CustomCarryHandler (pl.asie.charset.api.carry.CustomCarryHandler)1 IMovable (pl.asie.charset.api.lib.IMovable)1 DefaultAudioReceiver (pl.asie.charset.lib.capability.audio.DefaultAudioReceiver)1 DefaultAudioSource (pl.asie.charset.lib.capability.audio.DefaultAudioSource)1 DefaultItemInsertionHandler (pl.asie.charset.lib.capability.inventory.DefaultItemInsertionHandler)1 DummyLaserReceiver (pl.asie.charset.lib.capability.laser.DummyLaserReceiver)1 DefaultPipeView (pl.asie.charset.lib.capability.pipe.DefaultPipeView)1 DummyBarrel (pl.asie.charset.lib.capability.storage.DummyBarrel)1 ThreeState (pl.asie.charset.lib.utils.ThreeState)1