Search in sources :

Example 16 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Binnie by ForestryMC.

the class CustomSlot method onSlotClick.

public void onSlotClick(final ContainerCraftGUI container, final int dragType, final ClickType modifier, final EntityPlayer player) {
    InventoryPlayer inventory = player.inventory;
    ItemStack stack = inventory.getItemStack();
    ItemStack slotStack = getStack().copy();
    // TODO modifier==mouseButton2?
    if (stack.isEmpty() || modifier == ClickType.PICKUP_ALL) {
        this.putStack(ItemStack.EMPTY);
    } else {
        stack = stack.copy();
        stack.setCount(1);
        this.putStack(stack);
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 17 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Binnie by ForestryMC.

the class ComponentDesignerRecipe method receiveGuiNBTOnServer.

@Override
public void receiveGuiNBTOnServer(final EntityPlayer player, final String name, final NBTTagCompound nbt) {
    if (name.equals("recipe")) {
        final InventoryPlayer playerInv = player.inventory;
        final ItemStack recipe = this.doRecipe(false);
        if (!recipe.isEmpty()) {
            if (playerInv.getItemStack().isEmpty()) {
                playerInv.setItemStack(this.doRecipe(true));
            } else if (playerInv.getItemStack().isItemEqual(recipe) && ItemStack.areItemStackTagsEqual(playerInv.getItemStack(), recipe)) {
                final int fit = recipe.getMaxStackSize() - (recipe.getCount() + playerInv.getItemStack().getCount());
                if (fit >= 0) {
                    this.doRecipe(true);
                    recipe.grow(playerInv.getItemStack().getCount());
                    playerInv.setItemStack(recipe);
                }
            }
            player.openContainer.detectAndSendChanges();
            if (player instanceof EntityPlayerMP) {
                ((EntityPlayerMP) player).updateHeldItem();
            }
        }
    } else if (name.equals("design")) {
        setDesign(Design.getDesignManager().getDesign(nbt.getInteger("d")));
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 18 with InventoryPlayer

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

the class BuildCraftContainer method slotClickPhantom.

// @Override
// public ItemStack slotClick(int slotNum, int mouseButton, ClickType clickType, EntityPlayer player) {
// Slot slot = slotNum < 0 ? null : (Slot) this.inventorySlots.get(slotNum);
// if (slot instanceof IPhantomSlot) {
// return slotClickPhantom(slot, mouseButton, clickType, player);
// }
// return super.slotClick(slotNum, mouseButton, clickType, player);
// }
private ItemStack slotClickPhantom(Slot slot, int mouseButton, ClickType clickType, EntityPlayer player) {
    ItemStack stack = null;
    if (mouseButton == 2) {
        if (((IPhantomSlot) slot).canAdjustCount()) {
            slot.putStack(null);
        }
    } else if (mouseButton == 0 || mouseButton == 1) {
        InventoryPlayer playerInv = player.inventory;
        slot.onSlotChanged();
        ItemStack stackSlot = slot.getStack();
        ItemStack stackHeld = playerInv.getItemStack();
        if (stackSlot != null) {
            stack = stackSlot.copy();
        }
        if (stackSlot == null) {
            if (stackHeld != null && slot.isItemValid(stackHeld)) {
                fillPhantomSlot(slot, stackHeld, mouseButton, clickType);
            }
        } else if (stackHeld == null) {
            adjustPhantomSlot(slot, mouseButton, clickType);
            slot.onPickupFromSlot(player, playerInv.getItemStack());
        } else if (slot.isItemValid(stackHeld)) {
            if (StackUtil.canMerge(stackSlot, stackHeld)) {
                adjustPhantomSlot(slot, mouseButton, clickType);
            } else {
                fillPhantomSlot(slot, stackHeld, mouseButton, clickType);
            }
        }
    }
    return stack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) ItemStack(net.minecraft.item.ItemStack)

Example 19 with InventoryPlayer

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

the class GuiBuildCraft method drawScreen.

/**
 * Draws the screen and all the components in it.
 */
@Override
public void drawScreen(int mouseX, int mouseY, float par3) {
    super.drawScreen(mouseX, mouseY, par3);
    int left = this.guiLeft;
    int top = this.guiTop;
    GlStateManager.disableDepth();
    GL11.glPushMatrix();
    GL11.glTranslatef(left, top, 0.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    RenderHelper.disableStandardItemLighting();
    InventoryPlayer playerInv = this.mc.thePlayer.inventory;
    if (playerInv.getItemStack() == null) {
        drawToolTips(container.getWidgets(), mouseX - left, mouseY - top, left, top);
        drawToolTips(buttonList, mouseX, mouseY, 0, 0);
        drawToolTips(inventorySlots.inventorySlots, mouseX, mouseY, 0, 0);
    }
    GL11.glPopMatrix();
    GlStateManager.enableDepth();
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer)

Example 20 with InventoryPlayer

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

the class FluidTankWidget method handleTankClick.

/**
 * Attempts to interact the currently held item (in the gui) with this tank. This will either attempt to fill or
 * drain the tank depending on what type of item is currently held.
 */
private void handleTankClick() {
    InventoryPlayer inv = container.getPlayer().inventory;
    ItemStack heldStack = inv.getItemStack();
    if (heldStack == null || heldStack.getItem() == null)
        return;
    Item heldItem = heldStack.getItem();
    if (FluidContainerRegistry.isEmptyContainer(heldStack)) {
        int capacity = FluidContainerRegistry.getContainerCapacity(tank.drain(1, false), heldStack);
        FluidStack potential = tank.drain(capacity, false);
        if (potential == null)
            return;
        ItemStack filled = FluidContainerRegistry.fillFluidContainer(potential, heldStack);
        if (filled == null)
            return;
        if (FluidContainerRegistry.getContainerCapacity(filled) != capacity)
            return;
        tank.drain(capacity, true);
        inv.setItemStack(filled);
        if (inv.player instanceof EntityPlayerMP) {
            ((EntityPlayerMP) inv.player).updateHeldItem();
        }
    } else if (FluidContainerRegistry.isFilledContainer(heldStack)) {
        FluidStack contained = FluidContainerRegistry.getFluidForFilledItem(heldStack);
        if (tank.fill(contained, false) != contained.amount)
            return;
        ItemStack drained = FluidContainerRegistry.drainFluidContainer(heldStack);
        if (drained == null)
            return;
        tank.fill(contained, true);
        inv.setItemStack(drained);
        if (inv.player instanceof EntityPlayerMP) {
            ((EntityPlayerMP) inv.player).updateHeldItem();
        }
    } else if (heldItem instanceof IFluidContainerItem) {
        IFluidContainerItem container = (IFluidContainerItem) heldItem;
        FluidStack held = container.getFluid(heldStack);
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IFluidContainerItem(net.minecraftforge.fluids.IFluidContainerItem) Item(net.minecraft.item.Item) IFluidContainerItem(net.minecraftforge.fluids.IFluidContainerItem) FluidStack(net.minecraftforge.fluids.FluidStack) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

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