Java Code Examples for net.minecraft.inventory.IInventory#hasCustomName()

The following examples show how to use net.minecraft.inventory.IInventory#hasCustomName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: SkyblockAddons   File: PlayerListener.java    License: MIT License 6 votes vote down vote up
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent e) {
    if (e.gui == null && GuiChest.class.equals(lastOpenedInventory)) {
        lastClosedInv = System.currentTimeMillis();
        lastOpenedInventory = null;
    }
    if (e.gui != null) {
        lastOpenedInventory = e.gui.getClass();

        if (e.gui instanceof GuiChest) {
            Minecraft mc = Minecraft.getMinecraft();
            IInventory chestInventory = ((GuiChest)e.gui).lowerChestInventory;
            if (chestInventory.hasCustomName()) {
                if (chestInventory.getDisplayName().getUnformattedText().contains("Backpack")) {
                    if (ThreadLocalRandom.current().nextInt(0, 2) == 0) {
                        mc.thePlayer.playSound("mob.horse.armor", 0.5F, 1);
                    } else {
                        mc.thePlayer.playSound("mob.horse.leather", 0.5F, 1);
                    }
                }
            }
        }
    }
}
 
Example 2
@Override
protected void drawGuiContainerForegroundLayer(int x, int y){
    if(getInvNameOffset() != null && te instanceof IInventory) {
        IInventory inv = (IInventory)te;
        String containerName = inv.hasCustomName() ? inv.getName() : I18n.format(inv.getName() + ".name");
        fontRenderer.drawString(containerName, xSize / 2 - fontRenderer.getStringWidth(containerName) / 2 + getInvNameOffset().x, 6 + getInvNameOffset().y, 4210752);
    }
    if(getInvTextOffset() != null) fontRenderer.drawString(I18n.format("container.inventory"), 8 + getInvTextOffset().x, ySize - 94 + getInvTextOffset().y, 4210752);
}
 
Example 3
Source Project: SkyblockAddons   File: GuiChestHook.java    License: MIT License 4 votes vote down vote up
public static void handleMouseClick(Slot slotIn, Container slots, IInventory lowerChestInventory, ReturnValue<?> returnValue) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    if (main.getUtils().getEnchantmentMatches().size() > 0) {
        if (slotIn != null && !slotIn.inventory.equals(Minecraft.getMinecraft().thePlayer.inventory) && slotIn.getHasStack()) {
            if (slotIn.getSlotIndex() == 13 && EnumUtils.InventoryType.getCurrentInventoryType() == EnumUtils.InventoryType.ENCHANTMENT_TABLE) {
                ItemStack[] enchantBottles = {slots.getSlot(29).getStack(), slots.getSlot(31).getStack(), slots.getSlot(33).getStack()};
                for (ItemStack bottle : enchantBottles) {
                    if (bottle != null && bottle.hasDisplayName()) {
                        if (bottle.getDisplayName().startsWith(ChatFormatting.GREEN + "Enchant Item")) {
                            Minecraft mc = Minecraft.getMinecraft();
                            List<String> toolip = bottle.getTooltip(mc.thePlayer, false);
                            if (toolip.size() > 2) {
                                String[] lines = toolip.get(2).split(Pattern.quote("* "));

                                if (lines.length > 1) {
                                    String enchantLine = lines[1];
                                    if (main.getUtils().enchantReforgeMatches(enchantLine)) {
                                        main.getUtils().playLoudSound("random.orb", 0.1);
                                        returnValue.cancel();
                                    }
                                }
                            }
                        } else if (bottle.getDisplayName().startsWith(ChatFormatting.RED + "Enchant Item")) {
                            // Stop player from removing item before the enchants have even loaded.
                            returnValue.cancel();
                        }
                    }
                }
            } else if (slotIn.getSlotIndex() == 22 && EnumUtils.InventoryType.getCurrentInventoryType() == EnumUtils.InventoryType.REFORGE_ANVIL) {
                Slot itemSlot = slots.getSlot(13);
                if (itemSlot != null && itemSlot.getHasStack()) {
                    ItemStack item = itemSlot.getStack();
                    if (item.hasDisplayName()) {
                        String reforge = main.getUtils().getReforgeFromItem(item);
                        if (reforge != null) {
                            if (main.getUtils().enchantReforgeMatches(reforge)) {
                                main.getUtils().playLoudSound("random.orb", 0.1);
                                returnValue.cancel();
                            }
                        }
                    }
                }
            }
        }
    }

    if (main.getConfigValues().isEnabled(Feature.STOP_DROPPING_SELLING_RARE_ITEMS) && !main.getUtils().isInDungeon() &&
            lowerChestInventory.hasCustomName() && NPCUtils.isFullMerchant(lowerChestInventory.getDisplayName().getUnformattedText())
            && slotIn != null && slotIn.inventory instanceof InventoryPlayer) {
        if (!main.getUtils().getItemDropChecker().canDropItem(slotIn)) {
            returnValue.cancel();
        }
    }
}
 
Example 4
Source Project: SkyblockAddons   File: GuiScreenHook.java    License: MIT License 4 votes vote down vote up
public static void renderBackpack(ItemStack stack, int x, int y, ReturnValue<?> returnValue) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    if (stack.getItem().equals(Items.skull) && main.getConfigValues().isEnabled(Feature.SHOW_BACKPACK_PREVIEW)) {
        if (main.getConfigValues().isEnabled(Feature.SHOW_BACKPACK_HOLDING_SHIFT) && !GuiScreen.isShiftKeyDown()) {
            return;
        }

        Container playerContainer = Minecraft.getMinecraft().thePlayer.openContainer;
        if (playerContainer instanceof ContainerChest) { // Avoid showing backpack preview in auction stuff.
            IInventory chestInventory = ((ContainerChest) playerContainer).getLowerChestInventory();
            if (chestInventory.hasCustomName()) {
                String chestName = chestInventory.getDisplayName().getUnformattedText();
                if (chestName.contains("Auction") || "Your Bids".equals(chestName)) {

                    // Show preview for backpacks in player inventory if enabled.
                    if (!main.getConfigValues().isEnabled(Feature.BACKPACK_PREVIEW_AH)) {
                        return;
                    }

                    /*
                    If the backpack is in the auction house window, ignore it.
                    Empty backpacks can't be listed in the auction.
                     */
                    for (int i = 0; i < chestInventory.getSizeInventory(); i++) {
                        if (ItemStack.areItemStackTagsEqual(chestInventory.getStackInSlot(i), stack)) {
                            return;
                        }
                    }
                }
            }
        }

        Backpack backpack = BackpackManager.getFromItem(stack);
        if (backpack != null) {
            backpack.setX(x);
            backpack.setY(y);
            if (isFreezeKeyDown() && System.currentTimeMillis() - lastBackpackFreezeKey > 500) {
                lastBackpackFreezeKey = System.currentTimeMillis();
                GuiContainerHook.setFreezeBackpack(!GuiContainerHook.isFreezeBackpack());
                main.getUtils().setBackpackToPreview(backpack);
            }
            if (!GuiContainerHook.isFreezeBackpack()) {
                main.getUtils().setBackpackToPreview(backpack);
            }
            main.getPlayerListener().onItemTooltip(new ItemTooltipEvent(stack, null, null, false));
            returnValue.cancel();
        }
    }
    if (GuiContainerHook.isFreezeBackpack()) {
        returnValue.cancel();
    }
}