Search in sources :

Example 1 with ContainerChest

use of net.minecraft.inventory.ContainerChest in project SpongeCommon by SpongePowered.

the class InventoryArchetypeRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    InventoryArchetype SLOT = new SlotArchetype(ImmutableMap.of(CustomInventory.INVENTORY_DIMENSION, new InventoryDimension(1, 1)));
    InventoryArchetype MENU_ROW;
    InventoryArchetype MENU_COLUMN;
    InventoryArchetype MENU_GRID;
    InventoryArchetype CHEST;
    InventoryArchetype DOUBLE_CHEST;
    InventoryArchetype FURNACE;
    InventoryArchetype DISPENSER;
    InventoryArchetype WORKBENCH;
    InventoryArchetype BREWING_STAND;
    InventoryArchetype HOPPER;
    InventoryArchetype BEACON;
    InventoryArchetype ANVIL;
    InventoryArchetype ENCHANTING_TABLE;
    InventoryArchetype VILLAGER;
    InventoryArchetype HORSE;
    InventoryArchetype HORSE_WITH_CHEST;
    InventoryArchetype PLAYER;
    InventoryArchetype CRAFTING;
    InventoryArchetype UNKNOWN;
    final SpongeInventoryArchetypeBuilder builder = new SpongeInventoryArchetypeBuilder();
    for (int i = 0; i < 9; i++) {
        builder.with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(SlotIndex.of(i)).build("minecraft:slot" + i, "Slot"));
    }
    MENU_ROW = builder.property(new InventoryDimension(9, 1)).build("sponge:menu_row", "Menu Row");
    MENU_COLUMN = builder.property(new InventoryDimension(9, 1)).build("sponge:menu_column", "Menu Column");
    MENU_GRID = builder.reset().with(MENU_ROW).with(MENU_ROW).with(MENU_ROW).property(new InventoryDimension(9, 3)).build("sponge:menu_grid", "Menu Grid");
    CHEST = builder.reset().with(MENU_GRID).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.chest")))).property(new GuiIdProperty(GuiIds.CHEST)).container((i, p) -> new ContainerChest(p.inventory, i, p)).build("minecraft:chest", "Chest");
    DOUBLE_CHEST = builder.reset().with(CHEST).property(new InventoryDimension(9, 6)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.chestDouble")))).property(new GuiIdProperty(GuiIds.CHEST)).container((i, p) -> new ContainerChest(p.inventory, i, p)).build("minecraft:double_chest", "DoubleChest");
    FURNACE = builder.reset().with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new SlotIndex(0)).build("minecraft:furnace_input", "FurnaceInput")).with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new SlotIndex(1)).property(AcceptsItems.of()).build("minecraft:furnace_fuel", "FurnaceFuel")).with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new SlotIndex(2)).property(AcceptsItems.of()).build("minecraft:furnace_output", "FurnaceOutput")).property(new InventoryTitle(Text.of(new SpongeTranslation("container.furnace")))).property(new InventoryDimension(3, 1)).property(new GuiIdProperty(GuiIds.FURNACE)).container((i, p) -> new ContainerFurnace(p.inventory, i)).build("minecraft:furnace", "Furnace");
    DISPENSER = builder.reset().with(MENU_GRID).property(new InventoryDimension(3, 3)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.dispenser")))).property(new GuiIdProperty(GuiIds.DISPENSER)).container((i, p) -> new ContainerDispenser(p.inventory, i)).build("minecraft:dispenser", "Dispenser");
    WORKBENCH = builder.reset().with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(3, 3)).build("minecraft:workbench_grid", "Workbench Grid")).with(SLOT).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.crafting")))).property(new GuiIdProperty(GuiIds.CRAFTING_TABLE)).container((i, p) -> {
        ContainerWorkbench container = new ContainerWorkbench(p.inventory, p.getEntityWorld(), p.getPosition());
        // Pre-Fills the container input with the items from the inventory
        for (int index = 0; index < container.craftMatrix.getSizeInventory(); index++) {
            container.craftMatrix.setInventorySlotContents(index, i.getStackInSlot(index));
        }
        return container;
    }).build("minecraft:workbench", "Workbench");
    BREWING_STAND = builder.reset().with(MENU_ROW).property(new InventoryDimension(5, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.brewing")))).property(new GuiIdProperty(GuiIds.BREWING_STAND)).container((i, p) -> new ContainerBrewingStand(p.inventory, i)).build("minecraft:brewing_stand", "BrewingStand");
    HOPPER = builder.reset().with(MENU_ROW).property(new InventoryDimension(5, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.hopper")))).property(new GuiIdProperty(GuiIds.HOPPER)).container((i, p) -> new ContainerHopper(p.inventory, i, p)).build("minecraft:hopper", "Hopper");
    BEACON = builder.reset().with(SLOT).property(new InventoryDimension(1, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.beacon")))).property(new GuiIdProperty(GuiIds.BEACON)).container((i, p) -> new ContainerBeacon(p.inventory, i)).build("minecraft:beacon", "Beacon");
    ENCHANTING_TABLE = builder.reset().with(SLOT).with(SLOT).property(new InventoryDimension(2, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.enchant")))).property(new GuiIdProperty(GuiIds.ENCHANTING_TABLE)).container((i, p) -> {
        ContainerEnchantment container = new ContainerEnchantment(p.inventory, p.getEntityWorld(), p.getPosition());
        // Pre-Fills the container with the items from the inventory
        for (int index = 0; index < container.tableInventory.getSizeInventory(); index++) {
            container.tableInventory.setInventorySlotContents(index, i.getStackInSlot(index));
        }
        return container;
    }).build("minecraft:enchanting_table", "EnchantingTable");
    ANVIL = builder.reset().with(SLOT).with(SLOT).with(SLOT).property(new InventoryDimension(3, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.repair")))).property(new GuiIdProperty(GuiIds.ANVIL)).container((i, p) -> {
        ContainerRepair container = new ContainerRepair(p.inventory, p.getEntityWorld(), p.getPosition(), p);
        // Pre-Fills the container input with the items from the inventory
        for (int index = 0; index < container.inputSlots.getSizeInventory(); index++) {
            container.inputSlots.setInventorySlotContents(index, i.getStackInSlot(index));
        }
        return container;
    }).build("minecraft:anvil", "Anvil");
    VILLAGER = builder.reset().with(SLOT).with(SLOT).with(SLOT).property(new InventoryDimension(3, 1)).property(new GuiIdProperty(GuiIds.VILLAGER)).container((i, p) -> {
        if (i instanceof CarriedInventory && ((CarriedInventory) i).getCarrier().isPresent() && ((CarriedInventory) i).getCarrier().get() instanceof IMerchant) {
            IMerchant merchant = ((IMerchant) ((CarriedInventory) i).getCarrier().get());
            ContainerMerchant container = new ContainerMerchant(p.inventory, merchant, p.getEntityWorld());
            // TODO Pre-Fill the Container?
            return container;
        }
        throw new IllegalArgumentException("Cannot open merchant inventory without a merchant as Carrier");
    }).build("minecraft:villager", "Villager");
    HORSE = builder.reset().with(SLOT).with(SLOT).property(new InventoryDimension(2, 1)).property(// hardcoded openGuiHorseInventory
    new GuiIdProperty(GuiIds.HORSE)).container((i, p) -> {
        if (i instanceof CarriedInventory && ((CarriedInventory) i).getCarrier().isPresent() && ((CarriedInventory) i).getCarrier().get() instanceof AbstractHorse) {
            AbstractHorse horse = ((AbstractHorse) ((CarriedInventory) i).getCarrier().get());
            return new ContainerHorseInventory(p.inventory, i, horse, p);
        }
        throw new IllegalArgumentException("Cannot open horse inventory without a horse as Carrier");
    }).build("minecraft:horse", "Horse");
    HORSE_WITH_CHEST = builder.reset().with(HORSE).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(5, 3)).build("horse_grid", "HorseGrid")).property(// hardcoded openGuiHorseInventory
    new GuiIdProperty(GuiIds.HORSE)).container((i, p) -> {
        if (i instanceof CarriedInventory && ((CarriedInventory) i).getCarrier().isPresent() && ((CarriedInventory) i).getCarrier().get() instanceof AbstractHorse) {
            AbstractHorse horse = ((AbstractHorse) ((CarriedInventory) i).getCarrier().get());
            // TODO size
            return new ContainerHorseInventory(p.inventory, i, horse, p);
        }
        throw new IllegalArgumentException("Cannot open horse inventory without a horse as Carrier");
    }).build("minecraft:horse_with_chest", "Horse with Chest");
    CRAFTING = builder.reset().with(SLOT).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(2, 2)).build("minecraft:crafting_grid", "Crafting Grid")).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.crafting")))).build("minecraft:crafting", "Crafting");
    PLAYER = builder.reset().with(CRAFTING).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(1, 4)).build("minecraft:armor", "Armor")).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(9, 3)).build("minecraft:player_main", "Player Main")).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(9, 1)).build("minecraft:player_hotbar", "Player Hotbar")).with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new InventoryDimension(1, 1)).build("minecraft:player_offhand", "Player Offhand")).build("minecraft:player", "Player");
    UNKNOWN = builder.reset().build("minecraft:unknown", "UKNOWN");
    registerAdditionalCatalog(SLOT);
    registerAdditionalCatalog(MENU_ROW);
    registerAdditionalCatalog(MENU_COLUMN);
    registerAdditionalCatalog(MENU_GRID);
    registerAdditionalCatalog(CHEST);
    SpongeInventoryBuilder.registerInventory(TileEntityChest.class, CHEST);
    SpongeInventoryBuilder.registerContainer(ContainerChest.class, CHEST);
    registerAdditionalCatalog(DOUBLE_CHEST);
    registerAdditionalCatalog(FURNACE);
    SpongeInventoryBuilder.registerInventory(TileEntityFurnace.class, FURNACE);
    SpongeInventoryBuilder.registerContainer(ContainerFurnace.class, FURNACE);
    registerAdditionalCatalog(DISPENSER);
    SpongeInventoryBuilder.registerInventory(TileEntityDispenser.class, DISPENSER);
    SpongeInventoryBuilder.registerInventory(TileEntityDropper.class, DISPENSER);
    SpongeInventoryBuilder.registerContainer(ContainerDispenser.class, DISPENSER);
    registerAdditionalCatalog(WORKBENCH);
    SpongeInventoryBuilder.registerContainer(ContainerWorkbench.class, WORKBENCH);
    registerAdditionalCatalog(BREWING_STAND);
    SpongeInventoryBuilder.registerInventory(TileEntityBrewingStand.class, BREWING_STAND);
    SpongeInventoryBuilder.registerContainer(ContainerBrewingStand.class, BREWING_STAND);
    registerAdditionalCatalog(HOPPER);
    SpongeInventoryBuilder.registerInventory(TileEntityHopper.class, HOPPER);
    SpongeInventoryBuilder.registerContainer(ContainerHopper.class, HOPPER);
    registerAdditionalCatalog(BEACON);
    SpongeInventoryBuilder.registerInventory(TileEntityBeacon.class, BEACON);
    SpongeInventoryBuilder.registerContainer(ContainerBeacon.class, BEACON);
    registerAdditionalCatalog(ENCHANTING_TABLE);
    SpongeInventoryBuilder.registerContainer(ContainerEnchantment.class, ENCHANTING_TABLE);
    registerAdditionalCatalog(ANVIL);
    SpongeInventoryBuilder.registerContainer(ContainerRepair.class, ANVIL);
    registerAdditionalCatalog(VILLAGER);
    // TODO internal Villager Inventory? make Villager Carrier?
    SpongeInventoryBuilder.registerContainer(ContainerMerchant.class, VILLAGER);
    registerAdditionalCatalog(HORSE);
    // TODO Horse IInventory? SpongeInventoryBuilder.registerInventory(EntityHorse.class, HORSE);
    SpongeInventoryBuilder.registerContainer(ContainerHorseInventory.class, HORSE);
    registerAdditionalCatalog(HORSE_WITH_CHEST);
    registerAdditionalCatalog(CRAFTING);
    registerAdditionalCatalog(PLAYER);
    registerAdditionalCatalog(UNKNOWN);
    // Helper Archetypes for Menu
    InventoryArchetype MENU_ICON;
    InventoryArchetype MENU_BUTTON;
    InventoryArchetype MENU_CHECKBOX;
    InventoryArchetype MENU_SPINNER;
    MENU_ICON = builder.reset().with(SLOT).build("sponge:menu_icon", "Menu Icon");
    MENU_BUTTON = builder.reset().with(MENU_ICON).build("sponge:menu_button", "Menu Button");
    MENU_CHECKBOX = builder.reset().with(MENU_ICON).build("sponge:menu_checkbox", "Menu Checkbox");
    MENU_SPINNER = builder.reset().with(MENU_ICON).build("sponge:menu_spinner", "Menu Spinner");
    registerAdditionalCatalog(MENU_ICON);
    registerAdditionalCatalog(MENU_BUTTON);
    registerAdditionalCatalog(MENU_CHECKBOX);
    registerAdditionalCatalog(MENU_SPINNER);
}
Also used : SlotArchetype(org.spongepowered.common.item.inventory.archetype.SlotArchetype) AbstractHorse(net.minecraft.entity.passive.AbstractHorse) SpongeTranslation(org.spongepowered.common.text.translation.SpongeTranslation) GuiIdProperty(org.spongepowered.api.item.inventory.property.GuiIdProperty) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) ContainerDispenser(net.minecraft.inventory.ContainerDispenser) ContainerHopper(net.minecraft.inventory.ContainerHopper) ContainerBeacon(net.minecraft.inventory.ContainerBeacon) IMerchant(net.minecraft.entity.IMerchant) ContainerHorseInventory(net.minecraft.inventory.ContainerHorseInventory) ContainerBrewingStand(net.minecraft.inventory.ContainerBrewingStand) SpongeInventoryArchetypeBuilder(org.spongepowered.common.item.inventory.archetype.SpongeInventoryArchetypeBuilder) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) ContainerWorkbench(net.minecraft.inventory.ContainerWorkbench) ContainerRepair(net.minecraft.inventory.ContainerRepair) ContainerFurnace(net.minecraft.inventory.ContainerFurnace) ContainerChest(net.minecraft.inventory.ContainerChest) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) ContainerMerchant(net.minecraft.inventory.ContainerMerchant) InventoryDimension(org.spongepowered.api.item.inventory.property.InventoryDimension) InventoryArchetype(org.spongepowered.api.item.inventory.InventoryArchetype) ContainerEnchantment(net.minecraft.inventory.ContainerEnchantment)

Example 2 with ContainerChest

use of net.minecraft.inventory.ContainerChest 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 == ItemStack.EMPTY) {
                        continue;
                    }
                    if (stack.getItem() instanceof CofferItem) {
                        toEvaluate.add(tf(stack));
                    } else {
                        toReturn.add(tf(stack));
                    }
                    chestInv.setInventorySlotContents(i, ItemStack.EMPTY);
                }
                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 3 with ContainerChest

use of net.minecraft.inventory.ContainerChest in project Random-Things by lumien231.

the class TileEntitySpecialChest method update.

/**
 * Like the old updateEntity(), except more generic.
 */
@Override
public void update() {
    int i = this.pos.getX();
    int j = this.pos.getY();
    int k = this.pos.getZ();
    ++this.ticksSinceSync;
    if (!this.world.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + i + j + k) % 200 == 0) {
        this.numPlayersUsing = 0;
        float f = 5.0F;
        for (EntityPlayer entityplayer : this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(i - 5.0F, j - 5.0F, k - 5.0F, i + 1 + 5.0F, j + 1 + 5.0F, k + 1 + 5.0F))) {
            if (entityplayer.openContainer instanceof ContainerChest) {
                IInventory iinventory = ((ContainerChest) entityplayer.openContainer).getLowerChestInventory();
                if (iinventory == this) {
                    ++this.numPlayersUsing;
                }
            }
        }
    }
    this.prevLidAngle = this.lidAngle;
    float f1 = 0.1F;
    if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) {
        double d1 = i + 0.5D;
        double d2 = k + 0.5D;
        this.world.playSound((EntityPlayer) null, d1, j + 0.5D, d2, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
    }
    if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) {
        float f2 = this.lidAngle;
        if (this.numPlayersUsing > 0) {
            this.lidAngle += 0.1F;
        } else {
            this.lidAngle -= 0.1F;
        }
        if (this.lidAngle > 1.0F) {
            this.lidAngle = 1.0F;
        }
        float f3 = 0.5F;
        if (this.lidAngle < 0.5F && f2 >= 0.5F) {
            double d3 = i + 0.5D;
            double d0 = k + 0.5D;
            this.world.playSound((EntityPlayer) null, d3, j + 0.5D, d0, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
        }
        if (this.lidAngle < 0.0F) {
            this.lidAngle = 0.0F;
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) ContainerChest(net.minecraft.inventory.ContainerChest) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 4 with ContainerChest

use of net.minecraft.inventory.ContainerChest 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, ItemStack.EMPTY);
            }
        }
    }
}
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 5 with ContainerChest

use of net.minecraft.inventory.ContainerChest in project MorePlanets by SteveKunG.

the class TileEntityTreasureChestMP method update.

@Override
public void update() {
    int i = this.pos.getX();
    int j = this.pos.getY();
    int k = this.pos.getZ();
    ++this.ticksSinceSync;
    float f;
    if (this.locked) {
        this.numPlayersUsing = 0;
    }
    if (!this.world.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + i + j + k) % 200 == 0) {
        this.numPlayersUsing = 0;
        f = 5.0F;
        List<EntityPlayer> list = this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(i - f, j - f, k - f, i + 1 + f, j + 1 + f, k + 1 + f));
        Iterator<EntityPlayer> iterator = list.iterator();
        while (iterator.hasNext()) {
            EntityPlayer player = iterator.next();
            if (player.openContainer instanceof ContainerChest) {
                IInventory iinventory = ((ContainerChest) player.openContainer).getLowerChestInventory();
                if (iinventory == this || iinventory instanceof InventoryLargeChest && ((InventoryLargeChest) iinventory).isPartOfLargeChest(this)) {
                    ++this.numPlayersUsing;
                }
            }
        }
    }
    this.prevLidAngle = this.lidAngle;
    f = this.world.provider instanceof IGalacticraftWorldProvider ? 0.05F : 0.1F;
    double d2;
    if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) {
        double d1 = i + 0.5D;
        d2 = k + 0.5D;
        this.world.playSound(null, d1, j + 0.5D, d2, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.provider instanceof IGalacticraftWorldProvider ? this.world.rand.nextFloat() * 0.1F + 0.6F : this.world.rand.nextFloat() * 0.1F + 0.9F);
    }
    if ((this.numPlayersUsing == 0 || this.locked) && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) {
        float f1 = this.lidAngle;
        if (this.numPlayersUsing == 0 || this.locked) {
            this.lidAngle -= f;
        } else {
            this.lidAngle += f;
        }
        if (this.lidAngle > 1.0F) {
            this.lidAngle = 1.0F;
        }
        float f2 = 0.5F;
        if (this.lidAngle < f2 && f1 >= f2) {
            d2 = i + 0.5D;
            double d0 = k + 0.5D;
            this.world.playSound(null, d2, j + 0.5D, d0, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.provider instanceof IGalacticraftWorldProvider ? this.world.rand.nextFloat() * 0.1F + 0.6F : this.world.rand.nextFloat() * 0.1F + 0.9F);
        }
        if (this.lidAngle < 0.0F) {
            this.lidAngle = 0.0F;
        }
    }
    super.update();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) ContainerChest(net.minecraft.inventory.ContainerChest) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

ContainerChest (net.minecraft.inventory.ContainerChest)5 IInventory (net.minecraft.inventory.IInventory)4 BigDecimal (java.math.BigDecimal)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ILockableContainer (net.minecraft.world.ILockableContainer)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 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 IMerchant (net.minecraft.entity.IMerchant)1 AbstractHorse (net.minecraft.entity.passive.AbstractHorse)1 ContainerBeacon (net.minecraft.inventory.ContainerBeacon)1 ContainerBrewingStand (net.minecraft.inventory.ContainerBrewingStand)1 ContainerDispenser (net.minecraft.inventory.ContainerDispenser)1 ContainerEnchantment (net.minecraft.inventory.ContainerEnchantment)1 ContainerFurnace (net.minecraft.inventory.ContainerFurnace)1 ContainerHopper (net.minecraft.inventory.ContainerHopper)1