Search in sources :

Example 76 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project ImmersiveEngineering by BluSunrize.

the class ContainerIEBase method slotClick.

@Nonnull
@Override
public ItemStack slotClick(int id, int button, ClickType clickType, EntityPlayer player) {
    Slot slot = id < 0 ? null : this.inventorySlots.get(id);
    if (!(slot instanceof IESlot.Ghost))
        return super.slotClick(id, button, clickType, player);
    // Spooky Ghost Slots!!!!
    ItemStack stack = ItemStack.EMPTY;
    ItemStack stackSlot = slot.getStack();
    if (!stackSlot.isEmpty())
        stack = stackSlot.copy();
    if (button == 2)
        slot.putStack(ItemStack.EMPTY);
    else if (button == 0 || button == 1) {
        InventoryPlayer playerInv = player.inventory;
        ItemStack stackHeld = playerInv.getItemStack();
        if (stackSlot.isEmpty()) {
            if (!stackHeld.isEmpty() && slot.isItemValid(stackHeld)) {
                slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
            }
        } else if (stackHeld.isEmpty()) {
            slot.putStack(ItemStack.EMPTY);
        } else if (slot.isItemValid(stackHeld)) {
            slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
        }
    } else if (button == 5) {
        InventoryPlayer playerInv = player.inventory;
        ItemStack stackHeld = playerInv.getItemStack();
        if (!slot.getHasStack()) {
            slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
        }
    }
    return stack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 77 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.

the class ChargeTickHandler method onPlayerSunlightChargeTick.

@SubscribeEvent
public void onPlayerSunlightChargeTick(TickEvent.PlayerTickEvent e) {
    time++;
    if (time < 20 || e.side != Side.SERVER)
        return;
    time = 0;
    EntityPlayer player = e.player;
    InventoryPlayer playerInv = player.inventory;
    if (player.worldObj.isDaytime() && !player.worldObj.isRaining() && Helper.canEntitySeeSky(player)) {
        // BAUBLES SUNLIGHT
        IBaublesItemHandler baublesInv = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null);
        for (int i = 0; i < baublesInv.getSlots(); i++) {
            ItemStack stack = baublesInv.getStackInSlot(i);
            if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
                ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
                if (sitem.isSunlightChargeable(stack, BAUBLES_SLOTS[i])) {
                    sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, BAUBLES_SLOTS[i]) * 20);
                }
            }
        }
        // MAIN
        for (int i = 0; i < playerInv.mainInventory.length; i++) {
            ItemStack stack = playerInv.mainInventory[i];
            if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
                ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
                if (sitem.isSunlightChargeable(stack, i)) {
                    sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, i) * 20);
                }
            }
        }
        // ARMOR
        for (int i = 0; i < playerInv.armorInventory.length; i++) {
            ItemStack stack = playerInv.armorInventory[i];
            if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
                ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
                if (sitem.isSunlightChargeable(stack, ARMOR_SLOTS[i])) {
                    sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, ARMOR_SLOTS[i]) * 20);
                }
            }
        }
        // OFFHAND
        for (ItemStack stack : playerInv.offHandInventory) {
            if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
                ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
                if (sitem.isSunlightChargeable(stack, OFFHAND_SLOTS[0])) {
                    sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, OFFHAND_SLOTS[0]) * 20);
                }
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IBaublesItemHandler(baubles.api.cap.IBaublesItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ISunlightChargeable(convenientadditions.api.item.charge.ISunlightChargeable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 78 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.

the class ContainerTransmutationTome method onContainerClosed.

@Override
public void onContainerClosed(EntityPlayer playerIn) {
    if (player.worldObj.isRemote)
        return;
    InventoryPlayer inventoryplayer = playerIn.inventory;
    if (inventoryplayer.getItemStack() != null) {
        playerIn.dropItem(inventoryplayer.getItemStack(), false);
        inventoryplayer.setItemStack((ItemStack) null);
    }
    if (handler.getStackInSlot(0) != null) {
        playerIn.dropItem(handler.getStackInSlot(0), false);
        handler.setStackInSlot(0, null);
    }
    if (handler.getStackInSlot(1) != null) {
        playerIn.dropItem(handler.getStackInSlot(1), false);
        handler.setStackInSlot(1, null);
    }
    if (out.getStackInSlot(0) != null) {
        playerIn.dropItem(out.getStackInSlot(0), false);
        out.setStackInSlot(0, null);
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer)

Example 79 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.

the class PlayerInventoryTickHandler method onPlayerInventoryTick.

@SubscribeEvent
public void onPlayerInventoryTick(TickEvent.PlayerTickEvent e) {
    EntityPlayer player = e.player;
    InventoryPlayer playerInv = player.inventory;
    // MAIN
    for (int i = 0; i < playerInv.mainInventory.length; i++) {
        ItemStack stack = playerInv.mainInventory[i];
        if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
            ((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, i, player);
            ;
        }
    }
    // ARMOR
    for (int i = 0; i < playerInv.armorInventory.length; i++) {
        ItemStack stack = playerInv.armorInventory[i];
        if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
            ((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, ARMOR_SLOTS[i], player);
            ;
        }
    }
    // OFFHAND
    for (ItemStack stack : playerInv.offHandInventory) {
        if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
            ((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, OFFHAND_SLOTS[0], player);
            ;
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerInventoryTick(convenientadditions.api.item.IPlayerInventoryTick) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 80 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project LogisticsPipes by RS485.

the class DummyContainer method slotClick.

/**
 * Clone/clear itemstacks for items
 */
@Nonnull
@Override
public ItemStack slotClick(int slotId, int mouseButton, @Nonnull ClickType shiftMode, @Nonnull EntityPlayer player) {
    lastClicked = System.currentTimeMillis();
    if (slotId < 0) {
        return superSlotClick(slotId, mouseButton, shiftMode, player);
    }
    Slot slot = inventorySlots.get(slotId);
    // debug dump
    if (LogisticsPipes.isDEBUG() && slot != null) {
        ItemStack stack = slot.getStack();
        if (!stack.isEmpty()) {
            ItemIdentifier.get(stack).debugDumpData(player.world.isRemote);
        }
    }
    if (slot == null)
        return ItemStack.EMPTY;
    if ((!(slot instanceof DummySlot) && !(slot instanceof UnmodifiableSlot) && !(slot instanceof FluidSlot) && !(slot instanceof ColorSlot) && !(slot instanceof HandelableSlot))) {
        ItemStack stack1 = superSlotClick(slotId, mouseButton, shiftMode, player);
        ItemStack stack2 = slot.getStack();
        if (!stack2.isEmpty() && stack2.getItem() instanceof ItemModule) {
            if (player instanceof EntityPlayerMP && MainProxy.isServer(player.world)) {
                ((EntityPlayerMP) player).sendSlotContents(this, slotId, stack2);
            }
        }
        return stack1;
    }
    InventoryPlayer inventoryplayer = player.inventory;
    ItemStack currentlyEquippedStack = inventoryplayer.getItemStack();
    // we get a leftclick *and* a doubleclick message if there's a doubleclick with no item on the pointer, filter it out
    if (currentlyEquippedStack.isEmpty() && shiftMode == ClickType.PICKUP_ALL) {
        return currentlyEquippedStack;
    }
    if (slot instanceof HandelableSlot) {
        overrideMCAntiSend = true;
        if (currentlyEquippedStack.isEmpty()) {
            inventoryplayer.setItemStack(((HandelableSlot) slot).getProvidedStack());
            return ItemStack.EMPTY;
        }
        return currentlyEquippedStack;
    }
    if (slot instanceof UnmodifiableSlot) {
        return currentlyEquippedStack;
    }
    handleDummyClick(slot, slotId, currentlyEquippedStack, mouseButton, shiftMode, player);
    return currentlyEquippedStack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(net.minecraft.inventory.Slot) IFuzzySlot(logisticspipes.interfaces.IFuzzySlot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) ItemModule(logisticspipes.items.ItemModule) Nonnull(javax.annotation.Nonnull)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)83 ItemStack (net.minecraft.item.ItemStack)57 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 Item (net.minecraft.item.Item)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