Search in sources :

Example 1 with InventoryEffectRenderer

use of net.minecraft.client.renderer.InventoryEffectRenderer in project Galacticraft by micdoodle8.

the class LayoutManager method onPreDraw.

@Override
public void onPreDraw(GuiContainer gui) {
    if (// Reset the gui to the center of the screen, for potion effect offsets etc
    !isHidden() && isEnabled() && gui instanceof InventoryEffectRenderer) {
        gui.guiLeft = (gui.width - gui.xSize) / 2;
        gui.guiTop = (gui.height - gui.ySize) / 2;
        if (gui instanceof GuiContainerCreative && gui.buttonList.size() >= 2) {
            GuiButton button1 = (GuiButton) gui.buttonList.get(0);
            GuiButton button2 = (GuiButton) gui.buttonList.get(1);
            button1.xPosition = gui.guiLeft;
            button2.xPosition = gui.guiLeft + gui.xSize - 20;
        }
    }
}
Also used : GuiButton(net.minecraft.client.gui.GuiButton) InventoryEffectRenderer(net.minecraft.client.renderer.InventoryEffectRenderer) GuiContainerCreative(net.minecraft.client.gui.inventory.GuiContainerCreative)

Example 2 with InventoryEffectRenderer

use of net.minecraft.client.renderer.InventoryEffectRenderer in project Wurst-MC-1.12 by Wurst-Imperium.

the class AutoArmorMod method onUpdate.

@Override
public void onUpdate() {
    // wait for timer
    if (timer > 0) {
        timer--;
        return;
    }
    // check screen
    if (mc.currentScreen instanceof GuiContainer && !(mc.currentScreen instanceof InventoryEffectRenderer))
        return;
    // store slots and values of best armor pieces
    int[] bestArmorSlots = new int[4];
    int[] bestArmorValues = new int[4];
    // initialize with currently equipped armor
    for (int armorType = 0; armorType < 4; armorType++) {
        ItemStack oldArmor = WMinecraft.getPlayer().inventory.armorItemInSlot(armorType);
        if (!WItem.isNullOrEmpty(oldArmor) && oldArmor.getItem() instanceof ItemArmor)
            bestArmorValues[armorType] = ((ItemArmor) oldArmor.getItem()).damageReduceAmount;
        bestArmorSlots[armorType] = -1;
    }
    // search inventory for better armor
    for (int slot = 0; slot < 36; slot++) {
        ItemStack stack = WMinecraft.getPlayer().inventory.getStackInSlot(slot);
        if (WItem.isNullOrEmpty(stack) || !(stack.getItem() instanceof ItemArmor))
            continue;
        ItemArmor armor = (ItemArmor) stack.getItem();
        int armorType = WItem.getArmorType(armor);
        int armorValue = armor.damageReduceAmount;
        if (armorValue > bestArmorValues[armorType]) {
            bestArmorSlots[armorType] = slot;
            bestArmorValues[armorType] = armorValue;
        }
    }
    // equip better armor
    for (int armorType = 0; armorType < 4; armorType++) {
        // check if better armor was found
        int slot = bestArmorSlots[armorType];
        if (slot == -1)
            continue;
        // check if armor can be swapped
        // needs 1 free slot where it can put the old armor
        ItemStack oldArmor = WMinecraft.getPlayer().inventory.armorItemInSlot(armorType);
        if (WItem.isNullOrEmpty(oldArmor) || WMinecraft.getPlayer().inventory.getFirstEmptyStack() != -1) {
            // hotbar fix
            if (slot < 9)
                slot += 36;
            // swap armor
            if (!WItem.isNullOrEmpty(oldArmor))
                WPlayerController.windowClick_QUICK_MOVE(8 - armorType);
            WPlayerController.windowClick_QUICK_MOVE(slot);
            break;
        }
    }
    // set timer
    timer = 2;
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) InventoryEffectRenderer(net.minecraft.client.renderer.InventoryEffectRenderer) GuiContainer(net.minecraft.client.gui.inventory.GuiContainer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryEffectRenderer (net.minecraft.client.renderer.InventoryEffectRenderer)2 GuiButton (net.minecraft.client.gui.GuiButton)1 GuiContainer (net.minecraft.client.gui.inventory.GuiContainer)1 GuiContainerCreative (net.minecraft.client.gui.inventory.GuiContainerCreative)1 ItemArmor (net.minecraft.item.ItemArmor)1 ItemStack (net.minecraft.item.ItemStack)1