Search in sources :

Example 1 with ILockableContainer

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

the class GoldRushListener method onChestClose.

@Listener
public void onChestClose(InteractInventoryEvent.Close event) {
    Inventory inventory = event.getTargetInventory();
    if (inventory instanceof ContainerChest) {
        IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
        if (chestInv instanceof ILockableContainer) {
            String lockCode = ((ILockableContainer) chestInv).getLockCode().getLock();
            Optional<Player> optPlayer = Optional.ofNullable(tileEntityClaimMap.remove(lockCode));
            if (optPlayer.isPresent()) {
                Player player = optPlayer.get();
                ((ILockableContainer) chestInv).setLockCode(LockCode.EMPTY_CODE);
                Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
                if (!optInst.isPresent())
                    return;
                // TODO Sponge port
                GoldRushInstance inst = optInst.get();
                List<org.spongepowered.api.item.inventory.ItemStack> toEvaluate = new ArrayList<>();
                ArrayDeque<org.spongepowered.api.item.inventory.ItemStack> toReturn = new ArrayDeque<>();
                for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
                    ItemStack stack = chestInv.getStackInSlot(i);
                    if (stack == null) {
                        continue;
                    }
                    if (stack.getItem() instanceof CofferItem) {
                        toEvaluate.add(tf(stack));
                    } else {
                        toReturn.add(tf(stack));
                    }
                    chestInv.setInventorySlotContents(i, null);
                }
                BigDecimal value = BigDecimal.ZERO;
                for (org.spongepowered.api.item.inventory.ItemStack stack : toEvaluate) {
                    value = value.add(new BigDecimal(CofferValueMap.inst().getValue(Collections.singleton(stack)).orElse(BigInteger.ZERO)));
                }
                inst.cofferRisk.put(player.getUniqueId(), value);
                for (Inventory slot : player.getInventory().slots()) {
                    if (toReturn.isEmpty()) {
                        break;
                    }
                    if (slot.size() == 0) {
                        slot.set(toReturn.poll());
                    }
                }
                if (!toReturn.isEmpty()) {
                    new ItemDropper(player.getLocation()).dropStacks(toReturn, SpawnTypes.PLUGIN);
                }
                player.sendMessage(Text.of(TextColors.YELLOW, "You are now risking ", format(value), " coffers."));
                MessageChannel targetChannel = inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
                targetChannel.send(Text.of(TextColors.YELLOW, "Group risk of ", format(inst.getTotalRisk()), " coffers."));
                targetChannel.send(Text.of(TextColors.YELLOW, "Risk of lava ", inst.getChanceOfLava(), " / 100."));
                targetChannel.send(Text.of(TextColors.YELLOW, "Security system delay ", inst.getBaseTime(), " +/- ", inst.getTimeVariance(), " seconds."));
            }
        }
    }
}
Also used : ItemDropper(com.skelril.nitro.item.ItemDropper) ILockableContainer(net.minecraft.world.ILockableContainer) ContainerChest(net.minecraft.inventory.ContainerChest) IInventory(net.minecraft.inventory.IInventory) Player(org.spongepowered.api.entity.living.player.Player) BigDecimal(java.math.BigDecimal) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) CofferItem(com.skelril.skree.content.registry.item.currency.CofferItem) ItemStack(net.minecraft.item.ItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Listener(org.spongepowered.api.event.Listener)

Example 2 with ILockableContainer

use of net.minecraft.world.ILockableContainer in project Bookshelf by Darkhax-Minecraft.

the class BlockBasicChest method getContainer.

@Override
public ILockableContainer getContainer(World world, BlockPos pos, boolean locked) {
    final TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntityBasicChest)) {
        return null;
    } else {
        ILockableContainer myChest = (TileEntityBasicChest) tile;
        final IChestType myType = ((TileEntityBasicChest) tile).getType();
        if (!locked && this.isBlocked(world, pos)) {
            return null;
        } else {
            for (final EnumFacing facing : EnumFacing.Plane.HORIZONTAL) {
                final BlockPos adjPos = pos.offset(facing);
                final TileEntity adjTile = world.getTileEntity(adjPos);
                if (world.getBlockState(adjPos).getBlock() == this && adjTile instanceof TileEntityBasicChest && ((TileEntityBasicChest) adjTile).getType() == myType) {
                    if (this.isBlocked(world, adjPos)) {
                        return null;
                    }
                    if (facing != EnumFacing.WEST && facing != EnumFacing.NORTH) {
                        myChest = new InventoryLargeChest("container.chestDouble", myChest, (TileEntityBasicChest) adjTile);
                    } else {
                        myChest = new InventoryLargeChest("container.chestDouble", (TileEntityBasicChest) adjTile, myChest);
                    }
                }
            }
            return myChest;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) TileEntityBasicChest(net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with ILockableContainer

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

the class BlockInfectedChest method getLockableContainer.

@Override
public ILockableContainer getLockableContainer(World world, BlockPos pos) {
    TileEntity tileentity = world.getTileEntity(pos);
    if (!(tileentity instanceof TileEntityInfectedChest)) {
        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 TileEntityInfectedChest) {
                        if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (ILockableContainer) object, (TileEntityInfectedChest) tileentity1);
                        } else {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (TileEntityInfectedChest) tileentity1, (ILockableContainer) object);
                        }
                    }
                }
            }
            return (ILockableContainer) object;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) TileEntityInfectedChest(stevekung.mods.moreplanets.module.planets.nibiru.tileentity.TileEntityInfectedChest) 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 4 with ILockableContainer

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

the class BlockChestMP method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    } else {
        ILockableContainer ilockablecontainer = this.getLockableContainer(world, pos);
        if (ilockablecontainer != null) {
            player.displayGUIChest(ilockablecontainer);
            player.addStat(StatList.CHEST_OPENED);
        }
        return true;
    }
}
Also used : ILockableContainer(net.minecraft.world.ILockableContainer)

Example 5 with ILockableContainer

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

the class BlockCheeseSporeChest method getLockableContainer.

@Override
public ILockableContainer getLockableContainer(World world, BlockPos pos) {
    TileEntity tileentity = world.getTileEntity(pos);
    if (!(tileentity instanceof TileEntityCheeseSporeChest)) {
        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 TileEntityCheeseSporeChest) {
                        if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (ILockableContainer) object, (TileEntityCheeseSporeChest) tileentity1);
                        } else {
                            object = new InventoryLargeChest(GCCoreUtil.translate("container.chestDouble"), (TileEntityCheeseSporeChest) tileentity1, (ILockableContainer) object);
                        }
                    }
                }
            }
            return (ILockableContainer) object;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) TileEntityCheeseSporeChest(stevekung.mods.moreplanets.module.planets.chalos.tileentity.TileEntityCheeseSporeChest) 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)

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