Search in sources :

Example 6 with ILockableContainer

use of net.minecraft.world.ILockableContainer in project Skree by Skelril.

the class GoldRushListener method onChestOpen.

@Listener
public void onChestOpen(InteractInventoryEvent.Open event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent())
        return;
    GoldRushInstance inst = optInst.get();
    Inventory inventory = event.getTargetInventory();
    if (!inst.isLocked() && inventory instanceof ContainerChest) {
        IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
        if (chestInv instanceof ILockableContainer) {
            LockCode newLockCode = new LockCode(UUID.randomUUID().toString());
            tileEntityClaimMap.put(newLockCode.getLock(), player);
            ((ILockableContainer) chestInv).setLockCode(newLockCode);
            BigDecimal risk = Optional.ofNullable(inst.cofferRisk.get(player.getUniqueId())).orElse(BigDecimal.ZERO);
            Collection<org.spongepowered.api.item.inventory.ItemStack> queue = CofferValueMap.inst().satisfy(risk.toBigInteger());
            Iterator<org.spongepowered.api.item.inventory.ItemStack> it = queue.iterator();
            for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
                if (it.hasNext()) {
                    chestInv.setInventorySlotContents(i, tf(it.next()));
                    continue;
                }
                chestInv.setInventorySlotContents(i, null);
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) BigDecimal(java.math.BigDecimal) ILockableContainer(net.minecraft.world.ILockableContainer) ContainerChest(net.minecraft.inventory.ContainerChest) LockCode(net.minecraft.world.LockCode) ItemStack(net.minecraft.item.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Listener(org.spongepowered.api.event.Listener)

Example 7 with ILockableContainer

use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.

the class BlockChalosAncientChest method getLockableContainer.

public ILockableContainer getLockableContainer(World world, BlockPos pos) {
    TileEntity tileentity = world.getTileEntity(pos);
    if (!(tileentity instanceof TileEntityChalosAncientChest)) {
        return null;
    } else {
        Object object = tileentity;
        if (this.isBlocked(world, pos)) {
            return null;
        } else {
            Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
            while (iterator.hasNext()) {
                EnumFacing enumfacing = (EnumFacing) iterator.next();
                BlockPos blockpos1 = pos.offset(enumfacing);
                Block block = world.getBlockState(blockpos1).getBlock();
                if (block == this) {
                    if (this.isBlocked(world, blockpos1)) {
                        return null;
                    }
                    TileEntity tileentity1 = world.getTileEntity(blockpos1);
                    if (tileentity1 instanceof TileEntityChalosAncientChest) {
                        if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chalos.ancientchest.name"), (ILockableContainer) object, (TileEntityChalosAncientChest) tileentity1);
                        } else {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chalos.ancientchest.name"), (TileEntityChalosAncientChest) tileentity1, (ILockableContainer) object);
                        }
                    }
                }
            }
            return (ILockableContainer) object;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) TileEntityChalosAncientChest(stevekung.mods.moreplanets.module.planets.chalos.tileentity.TileEntityChalosAncientChest) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 8 with ILockableContainer

use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.

the class BlockNibiruAncientChest method getLockableContainer.

public ILockableContainer getLockableContainer(World world, BlockPos pos) {
    TileEntity tileentity = world.getTileEntity(pos);
    if (!(tileentity instanceof TileEntityNibiruAncientChest)) {
        return null;
    } else {
        Object object = tileentity;
        if (this.isBlocked(world, pos)) {
            return null;
        } else {
            Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
            while (iterator.hasNext()) {
                EnumFacing enumfacing = (EnumFacing) iterator.next();
                BlockPos blockpos1 = pos.offset(enumfacing);
                Block block = world.getBlockState(blockpos1).getBlock();
                if (block == this) {
                    if (this.isBlocked(world, blockpos1)) {
                        return null;
                    }
                    TileEntity tileentity1 = world.getTileEntity(blockpos1);
                    if (tileentity1 instanceof TileEntityNibiruAncientChest) {
                        if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.nibiru.ancientchest.name"), (ILockableContainer) object, (TileEntityNibiruAncientChest) tileentity1);
                        } else {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.nibiru.ancientchest.name"), (TileEntityNibiruAncientChest) tileentity1, (ILockableContainer) object);
                        }
                    }
                }
            }
            return (ILockableContainer) object;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) TileEntityNibiruAncientChest(stevekung.mods.moreplanets.module.planets.nibiru.tileentity.TileEntityNibiruAncientChest) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 9 with ILockableContainer

use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.

the class BlockAlienBerryChest method getLockableContainer.

@Override
public ILockableContainer getLockableContainer(World world, BlockPos pos) {
    TileEntity tileentity = world.getTileEntity(pos);
    if (!(tileentity instanceof TileEntityAlienBerryChest)) {
        return null;
    } else {
        Object object = tileentity;
        if (this.isBlocked(world, pos)) {
            return null;
        } else {
            Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
            while (iterator.hasNext()) {
                EnumFacing enumfacing = (EnumFacing) iterator.next();
                BlockPos blockpos1 = pos.offset(enumfacing);
                Block block = world.getBlockState(blockpos1).getBlock();
                if (block == this) {
                    if (this.isBlocked(world, blockpos1)) {
                        return null;
                    }
                    TileEntity tileentity1 = world.getTileEntity(blockpos1);
                    if (tileentity1 instanceof TileEntityAlienBerryChest) {
                        if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (ILockableContainer) object, (TileEntityAlienBerryChest) tileentity1);
                        } else {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (TileEntityAlienBerryChest) tileentity1, (ILockableContainer) object);
                        }
                    }
                }
            }
            return (ILockableContainer) object;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) TileEntityAlienBerryChest(stevekung.mods.moreplanets.module.planets.nibiru.tileentity.TileEntityAlienBerryChest) BlockPos(net.minecraft.util.math.BlockPos)

Example 10 with ILockableContainer

use of net.minecraft.world.ILockableContainer in project MorePlanets by SteveKunG.

the class BlockDionaAncientChest method getLockableContainer.

public ILockableContainer getLockableContainer(World world, BlockPos pos) {
    TileEntity tileentity = world.getTileEntity(pos);
    if (!(tileentity instanceof TileEntityDionaAncientChest)) {
        return null;
    } else {
        Object object = tileentity;
        if (this.isBlocked(world, pos)) {
            return null;
        } else {
            Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
            while (iterator.hasNext()) {
                EnumFacing enumfacing = (EnumFacing) iterator.next();
                BlockPos blockpos1 = pos.offset(enumfacing);
                Block block = world.getBlockState(blockpos1).getBlock();
                if (block == this) {
                    if (this.isBlocked(world, blockpos1)) {
                        return null;
                    }
                    TileEntity tileentity1 = world.getTileEntity(blockpos1);
                    if (tileentity1 instanceof TileEntityDionaAncientChest) {
                        if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.diona.ancientchest.name"), (ILockableContainer) object, (TileEntityDionaAncientChest) tileentity1);
                        } else {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.diona.ancientchest.name"), (TileEntityDionaAncientChest) tileentity1, (ILockableContainer) object);
                        }
                    }
                }
            }
            return (ILockableContainer) object;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TileEntityDionaAncientChest(stevekung.mods.moreplanets.module.planets.diona.tileentity.TileEntityDionaAncientChest)

Aggregations

ILockableContainer (net.minecraft.world.ILockableContainer)10 InventoryLargeChest (net.minecraft.inventory.InventoryLargeChest)7 TileEntity (net.minecraft.tileentity.TileEntity)7 EnumFacing (net.minecraft.util.EnumFacing)7 BlockPos (net.minecraft.util.math.BlockPos)7 Iterator (java.util.Iterator)6 Block (net.minecraft.block.Block)6 BigDecimal (java.math.BigDecimal)2 ContainerChest (net.minecraft.inventory.ContainerChest)2 IInventory (net.minecraft.inventory.IInventory)2 ItemStack (net.minecraft.item.ItemStack)2 Listener (org.spongepowered.api.event.Listener)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 ItemDropper (com.skelril.nitro.item.ItemDropper)1 CofferItem (com.skelril.skree.content.registry.item.currency.CofferItem)1 TileEntityBasicChest (net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest)1 IChestType (net.darkhax.bookshelf.builder.ChestBuilder.IChestType)1 LockCode (net.minecraft.world.LockCode)1 Player (org.spongepowered.api.entity.living.player.Player)1 MessageChannel (org.spongepowered.api.text.channel.MessageChannel)1