Search in sources :

Example 21 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Railcraft by Railcraft.

the class GuiContainerRailcraft method drawScreen.

/**
 * Draws the screen and all the components in it.
 */
@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
    drawDefaultBackground();
    super.drawScreen(mouseX, mouseY, par3);
    int left = guiLeft;
    int top = guiTop;
    OpenGL.glDisable(GL11.GL_LIGHTING);
    OpenGL.glDisable(GL11.GL_DEPTH_TEST);
    OpenGL.glPushMatrix();
    OpenGL.glTranslatef((float) left, (float) top, 0.0F);
    OpenGL.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    RenderHelper.disableStandardItemLighting();
    InventoryPlayer playerInv = mc.player.inventory;
    if (playerInv.getItemStack().isEmpty()) {
        int mX = mouseX - left;
        int mY = mouseY - top;
        for (Widget element : container.getWidgets()) {
            if (element.hidden)
                continue;
            ToolTip tips = element.getToolTip();
            if (tips == null)
                continue;
            boolean mouseOver = element.isMouseOver(mX, mY);
            tips.onTick(mouseOver);
            if (mouseOver && tips.isReady()) {
                tips.refresh();
                drawToolTips(tips, mouseX, mouseY);
            }
        }
        for (GuiButton button : buttonList) {
            if (!(button instanceof GuiBetterButton))
                continue;
            GuiBetterButton<?> betterButton = (GuiBetterButton<?>) button;
            if (!betterButton.visible)
                continue;
            ToolTip tips = betterButton.getToolTip();
            if (tips == null)
                continue;
            boolean mouseOver = betterButton.isMouseOverButton(mouseX, mouseY);
            tips.onTick(mouseOver);
            if (mouseOver && tips.isReady()) {
                tips.refresh();
                drawToolTips(tips, mouseX, mouseY);
            }
        }
        for (Object obj : inventorySlots.inventorySlots) {
            if (!(obj instanceof SlotRailcraft))
                continue;
            SlotRailcraft slot = (SlotRailcraft) obj;
            if (!slot.getStack().isEmpty())
                continue;
            ToolTip tips = slot.getToolTip();
            if (tips == null)
                continue;
            boolean mouseOver = isMouseOverSlot(slot, mouseX, mouseY);
            tips.onTick(mouseOver);
            if (mouseOver && tips.isReady()) {
                tips.refresh();
                drawToolTips(tips, mouseX, mouseY);
            }
        }
    }
    OpenGL.glPopMatrix();
    OpenGL.glEnable(GL11.GL_LIGHTING);
    OpenGL.glEnable(GL11.GL_DEPTH_TEST);
    renderHoveredToolTip(mouseX, mouseY);
}
Also used : ToolTip(mods.railcraft.common.gui.tooltips.ToolTip) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) GuiButton(net.minecraft.client.gui.GuiButton) GuiBetterButton(mods.railcraft.client.gui.buttons.GuiBetterButton) Widget(mods.railcraft.common.gui.widgets.Widget) SlotRailcraft(mods.railcraft.common.gui.slots.SlotRailcraft)

Example 22 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project BiomesOPlenty by Glitchfiend.

the class BlockBOPPlant method onEntityCollidedWithBlock.

@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
    switch((BOPPlants) state.getValue(this.variantProperty)) {
        case POISONIVY:
            // poison ivy poisons players who walk into it, unless they're wearing boots and pants
            if (entity instanceof EntityPlayer) {
                InventoryPlayer inventory = ((EntityPlayer) entity).inventory;
                if (inventory.armorInventory.get(0) != ItemStack.EMPTY && inventory.armorInventory.get(1) != ItemStack.EMPTY) {
                    break;
                }
                ((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.POISON, 100));
            }
            break;
        case THORN:
        case TINYCACTUS:
            // thorns and tiny cacti damage players who walk into them, unless they're wearing boots and pants
            if (entity instanceof EntityPlayer) {
                InventoryPlayer inventory = ((EntityPlayer) entity).inventory;
                if (inventory.armorInventory.get(0) != ItemStack.EMPTY && inventory.armorInventory.get(1) != ItemStack.EMPTY) {
                    break;
                }
                entity.attackEntityFrom(DamageSource.CACTUS, 1);
            }
            break;
        default:
            break;
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BOPPlants(biomesoplenty.api.enums.BOPPlants)

Example 23 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Armourers-Workshop by RiskyKen.

the class UtilPlayer method consumeInventoryItemCount.

public static void consumeInventoryItemCount(EntityPlayer player, Item item, int count) {
    int removeCount = count;
    InventoryPlayer inventory = player.inventory;
    for (int i = 0; i < inventory.mainInventory.length; i++) {
        if (inventory.mainInventory[i].getItem() == item) {
            if (inventory.mainInventory[i].stackSize >= removeCount) {
                removeCount -= inventory.mainInventory[i].stackSize;
                inventory.mainInventory[i] = null;
            } else {
                inventory.mainInventory[i].stackSize = removeCount;
                removeCount = 0;
            }
        }
        if (removeCount < 1) {
            return;
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer)

Example 24 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Minechem by iopleke.

the class ContainerWithFakeSlots method superSlotClick.

public ItemStack superSlotClick(int slotNum, int mouseButton, int isShiftPressed, EntityPlayer entityPlayer) {
    ItemStack itemstack = null;
    InventoryPlayer inventoryplayer = entityPlayer.inventory;
    int i1;
    ItemStack itemstack3;
    if (isShiftPressed == 5) {
        int l = this.field_94536_g;
        this.field_94536_g = func_94532_c(mouseButton);
        if ((l != 1 || this.field_94536_g != 2) && l != this.field_94536_g) {
            this.func_94533_d();
        } else if (inventoryplayer.getItemStack() == null) {
            this.func_94533_d();
        } else if (this.field_94536_g == 0) {
            this.field_94535_f = func_94529_b(mouseButton);
            if (func_94528_d(this.field_94535_f)) {
                this.field_94536_g = 1;
                this.field_94537_h.clear();
            } else {
                this.func_94533_d();
            }
        } else if (this.field_94536_g == 1) {
            Slot slot = (Slot) this.inventorySlots.get(slotNum);
            if (slot != null && func_94527_a(slot, inventoryplayer.getItemStack(), true) && slot.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize > this.field_94537_h.size() && this.canDragIntoSlot(slot)) {
                this.field_94537_h.add(slot);
            }
        } else if (this.field_94536_g == 2) {
            if (!this.field_94537_h.isEmpty()) {
                itemstack3 = inventoryplayer.getItemStack().copy();
                i1 = inventoryplayer.getItemStack().stackSize;
                Iterator iterator = this.field_94537_h.iterator();
                while (iterator.hasNext()) {
                    Slot slot1 = (Slot) iterator.next();
                    if (slot1 != null && func_94527_a(slot1, inventoryplayer.getItemStack(), true) && slot1.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize >= this.field_94537_h.size() && this.canDragIntoSlot(slot1)) {
                        ItemStack itemstack1 = itemstack3.copy();
                        int j1 = slot1.getHasStack() ? slot1.getStack().stackSize : 0;
                        func_94525_a(this.field_94537_h, this.field_94535_f, itemstack1, j1);
                        if (itemstack1.stackSize > itemstack1.getMaxStackSize()) {
                            itemstack1.stackSize = itemstack1.getMaxStackSize();
                        }
                        if (itemstack1.stackSize > slot1.getSlotStackLimit()) {
                            itemstack1.stackSize = slot1.getSlotStackLimit();
                        }
                        i1 -= itemstack1.stackSize - j1;
                        slot1.putStack(itemstack1);
                    }
                }
                itemstack3.stackSize = i1;
                if (itemstack3.stackSize <= 0) {
                    itemstack3 = null;
                }
                inventoryplayer.setItemStack(itemstack3);
            }
            this.func_94533_d();
        } else {
            this.func_94533_d();
        }
    } else if (this.field_94536_g != 0) {
        this.func_94533_d();
    } else {
        Slot slot2;
        int l1;
        ItemStack itemstack5;
        if ((isShiftPressed == 0 || isShiftPressed == 1) && (mouseButton == 0 || mouseButton == 1)) {
            if (slotNum == -999) {
                if (inventoryplayer.getItemStack() != null && slotNum == -999) {
                    if (mouseButton == 0) {
                        entityPlayer.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), true);
                        inventoryplayer.setItemStack(null);
                    }
                    if (mouseButton == 1) {
                        entityPlayer.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack().splitStack(1), true);
                        if (inventoryplayer.getItemStack().stackSize == 0) {
                            inventoryplayer.setItemStack(null);
                        }
                    }
                }
            } else if (isShiftPressed == 1) {
                if (slotNum < 0) {
                    return null;
                }
                slot2 = (Slot) this.inventorySlots.get(slotNum);
                if (slot2 != null && slot2.canTakeStack(entityPlayer)) {
                    itemstack3 = this.transferStackInSlot(entityPlayer, slotNum);
                    if (itemstack3 != null) {
                        Item item = itemstack3.getItem();
                        itemstack = itemstack3.copy();
                        if (slot2.getStack() != null && slot2.getStack().getItem() == item) {
                            this.retrySlotClick(slotNum, mouseButton, true, entityPlayer);
                        }
                    }
                }
            } else {
                if (slotNum < 0) {
                    return null;
                }
                slot2 = (Slot) this.inventorySlots.get(slotNum);
                if (slot2 != null) {
                    itemstack3 = slot2.getStack();
                    ItemStack itemstack4 = inventoryplayer.getItemStack();
                    if (itemstack3 != null) {
                        itemstack = itemstack3.copy();
                    }
                    if (itemstack3 == null) {
                        if (itemstack4 != null && slot2.isItemValid(itemstack4)) {
                            l1 = mouseButton == 0 ? itemstack4.stackSize : 1;
                            if (l1 > slot2.getSlotStackLimit()) {
                                l1 = slot2.getSlotStackLimit();
                            }
                            if (itemstack4.stackSize >= l1) {
                                slot2.putStack(itemstack4.splitStack(l1));
                            }
                            if (itemstack4.stackSize == 0) {
                                inventoryplayer.setItemStack(null);
                            }
                        }
                    } else if (slot2.canTakeStack(entityPlayer)) {
                        if (itemstack4 == null) {
                            l1 = mouseButton == 0 ? itemstack3.stackSize : (itemstack3.stackSize + 1) / 2;
                            itemstack5 = slot2.decrStackSize(l1);
                            inventoryplayer.setItemStack(itemstack5);
                            if (itemstack3.stackSize == 0) {
                                slot2.putStack(null);
                            }
                            slot2.onPickupFromSlot(entityPlayer, inventoryplayer.getItemStack());
                        } else if (slot2.isItemValid(itemstack4)) {
                            if (itemstack3.getItem() == itemstack4.getItem() && itemstack3.getItemDamage() == itemstack4.getItemDamage() && ItemStack.areItemStackTagsEqual(itemstack3, itemstack4)) {
                                l1 = mouseButton == 0 ? itemstack4.stackSize : 1;
                                if (l1 > slot2.getSlotStackLimit() - itemstack3.stackSize) {
                                    l1 = slot2.getSlotStackLimit() - itemstack3.stackSize;
                                }
                                if (l1 > itemstack4.getMaxStackSize() - itemstack3.stackSize) {
                                    l1 = itemstack4.getMaxStackSize() - itemstack3.stackSize;
                                }
                                itemstack4.splitStack(l1);
                                if (itemstack4.stackSize == 0) {
                                    inventoryplayer.setItemStack(null);
                                }
                                itemstack3.stackSize += l1;
                            } else if (itemstack4.stackSize <= slot2.getSlotStackLimit()) {
                                slot2.putStack(itemstack4);
                                inventoryplayer.setItemStack(itemstack3);
                            }
                        } else if (itemstack3.getItem() == itemstack4.getItem() && itemstack4.getMaxStackSize() > 1 && (!itemstack3.getHasSubtypes() || itemstack3.getItemDamage() == itemstack4.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemstack3, itemstack4)) {
                            l1 = itemstack3.stackSize;
                            if (l1 > 0 && l1 + itemstack4.stackSize <= itemstack4.getMaxStackSize()) {
                                itemstack4.stackSize += l1;
                                itemstack3 = slot2.decrStackSize(l1);
                                if (itemstack3.stackSize == 0) {
                                    slot2.putStack(null);
                                }
                                slot2.onPickupFromSlot(entityPlayer, inventoryplayer.getItemStack());
                            }
                        }
                    }
                    slot2.onSlotChanged();
                }
            }
        } else if (isShiftPressed == 2 && mouseButton >= 0 && mouseButton < 9) {
            slot2 = (Slot) this.inventorySlots.get(slotNum);
            if (slot2.canTakeStack(entityPlayer)) {
                itemstack3 = inventoryplayer.getStackInSlot(mouseButton);
                boolean flag = itemstack3 == null || slot2.inventory == inventoryplayer && slot2.isItemValid(itemstack3);
                l1 = -1;
                if (!flag) {
                    l1 = inventoryplayer.getFirstEmptyStack();
                    flag |= l1 > -1;
                }
                if (slot2.getHasStack() && flag) {
                    itemstack5 = slot2.getStack();
                    inventoryplayer.setInventorySlotContents(mouseButton, itemstack5.copy());
                    if ((slot2.inventory != inventoryplayer || !slot2.isItemValid(itemstack3)) && itemstack3 != null) {
                        if (l1 > -1) {
                            inventoryplayer.addItemStackToInventory(itemstack3);
                            slot2.decrStackSize(itemstack5.stackSize);
                            slot2.putStack(null);
                            slot2.onPickupFromSlot(entityPlayer, itemstack5);
                        }
                    } else {
                        slot2.decrStackSize(itemstack5.stackSize);
                        slot2.putStack(itemstack3);
                        slot2.onPickupFromSlot(entityPlayer, itemstack5);
                    }
                } else if (!slot2.getHasStack() && itemstack3 != null && slot2.isItemValid(itemstack3)) {
                    inventoryplayer.setInventorySlotContents(mouseButton, null);
                    slot2.putStack(itemstack3);
                }
            }
        } else if (isShiftPressed == 3 && entityPlayer.capabilities.isCreativeMode && inventoryplayer.getItemStack() == null && slotNum >= 0) {
            slot2 = (Slot) this.inventorySlots.get(slotNum);
            if (slot2 != null && slot2.getHasStack()) {
                itemstack3 = slot2.getStack().copy();
                itemstack3.stackSize = itemstack3.getMaxStackSize();
                inventoryplayer.setItemStack(itemstack3);
            }
        } else if (isShiftPressed == 4 && inventoryplayer.getItemStack() == null && slotNum >= 0) {
            slot2 = (Slot) this.inventorySlots.get(slotNum);
            if (slot2 != null && slot2.getHasStack() && slot2.canTakeStack(entityPlayer)) {
                itemstack3 = slot2.decrStackSize(mouseButton == 0 ? 1 : slot2.getStack().stackSize);
                slot2.onPickupFromSlot(entityPlayer, itemstack3);
                entityPlayer.dropPlayerItemWithRandomChoice(itemstack3, true);
            }
        } else if (isShiftPressed == 6 && slotNum >= 0) {
            slot2 = (Slot) this.inventorySlots.get(slotNum);
            itemstack3 = inventoryplayer.getItemStack();
            if (itemstack3 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(entityPlayer))) {
                i1 = mouseButton == 0 ? 0 : this.inventorySlots.size() - 1;
                l1 = mouseButton == 0 ? 1 : -1;
                for (int i2 = 0; i2 < 2; ++i2) {
                    for (int j2 = i1; j2 >= 0 && j2 < this.inventorySlots.size() && itemstack3.stackSize < itemstack3.getMaxStackSize(); j2 += l1) {
                        Slot slot3 = (Slot) this.inventorySlots.get(j2);
                        if (slot3 instanceof SlotFake) {
                            continue;
                        }
                        if (slot3.getHasStack() && func_94527_a(slot3, itemstack3, true) && slot3.canTakeStack(entityPlayer) && this.func_94530_a(itemstack3, slot3) && (i2 != 0 || slot3.getStack().stackSize != slot3.getStack().getMaxStackSize())) {
                            int k1 = Math.min(itemstack3.getMaxStackSize() - itemstack3.stackSize, slot3.getStack().stackSize);
                            ItemStack itemstack2 = slot3.decrStackSize(k1);
                            itemstack3.stackSize += k1;
                            if (itemstack2.stackSize <= 0) {
                                slot3.putStack(null);
                            }
                            slot3.onPickupFromSlot(entityPlayer, itemstack2);
                        }
                    }
                }
            }
            this.detectAndSendChanges();
        }
    }
    return itemstack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Item(net.minecraft.item.Item) SlotFake(minechem.slot.SlotFake) Iterator(java.util.Iterator) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 25 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project PneumaticCraft by MineMaarten.

the class TileEntityAerialInterface method setInventorySlotContents.

@Override
public void setInventorySlotContents(int slot, ItemStack itemStack) {
    if (slot < 4) {
        inventory[slot] = itemStack;
        if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
            itemStack.stackSize = getInventoryStackLimit();
        }
    } else {
        EntityPlayer player = getPlayer();
        if (dispenserUpgradeInserted) {
            if (itemStack != null) {
                int startValue = itemStack.stackSize;
                while (itemStack.stackSize > 0) {
                    ItemStack remainingItem = itemStack.onFoodEaten(player.worldObj, player);
                    remainingItem = ForgeEventFactory.onItemUseFinish(player, itemStack, 0, remainingItem);
                    if (remainingItem != null && remainingItem.stackSize > 0 && (remainingItem != itemStack || remainingItem.stackSize != startValue)) {
                        if (!player.inventory.addItemStackToInventory(remainingItem) && remainingItem.stackSize > 0) {
                            player.dropPlayerItemWithRandomChoice(remainingItem, false);
                        }
                    }
                    if (itemStack.stackSize == startValue)
                        break;
                }
            }
        } else {
            InventoryPlayer inventoryPlayer = player != null ? player.inventory : null;
            if (inventoryPlayer != null) {
                inventoryPlayer.setInventorySlotContents(slot - 4, itemStack);
            } else if (worldObj != null && !worldObj.isRemote) {
                EntityItem item = new EntityItem(worldObj, xCoord, yCoord, zCoord, itemStack);
                worldObj.spawnEntityInWorld(item);
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)81 ItemStack (net.minecraft.item.ItemStack)56 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)8 Item (net.minecraft.item.Item)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 ArrayList (java.util.ArrayList)5 Nonnull (javax.annotation.Nonnull)4 IFuzzySlot (logisticspipes.interfaces.IFuzzySlot)4 Button (com.minecolonies.blockout.controls.Button)3 EntityItem (net.minecraft.entity.item.EntityItem)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)2 TileProjectTable (com.bluepowermod.tile.tier1.TileProjectTable)2 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)2 Label (com.minecolonies.blockout.controls.Label)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 GameProfile (com.mojang.authlib.GameProfile)2 LinkedList (java.util.LinkedList)2