Search in sources :

Example 61 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project EnderIO by SleepyTrousers.

the class GuiInventoryPanel method ghostSlotClicked.

protected void ghostSlotClicked(GhostSlot slot, int x, int y, int button) {
    if (slot instanceof InvSlot) {
        InvSlot invSlot = (InvSlot) slot;
        InventoryDatabaseClient db = getDatabase();
        if (invSlot.entry != null && invSlot.getStack() != null && db != null) {
            int targetSlot;
            int count = Math.min(invSlot.getStack().getCount(), invSlot.getStack().getMaxStackSize());
            if (button == 0) {
                if (isShiftKeyDown()) {
                    InventoryPlayer playerInv = mc.player.inventory;
                    targetSlot = playerInv.getFirstEmptyStack();
                    if (targetSlot >= 0) {
                        targetSlot = getContainer().getSlotIndex(playerInv, targetSlot);
                    }
                    if (targetSlot < 0) {
                        return;
                    }
                } else {
                    targetSlot = -1;
                }
            } else if (button == 1) {
                targetSlot = -1;
                if (isCtrlKeyDown()) {
                    count = 1;
                } else {
                    count = (count + 1) / 2;
                }
            } else {
                return;
            }
            PacketHandler.INSTANCE.sendToServer(new PacketFetchItem(db.getGeneration(), invSlot.entry, targetSlot, count));
        }
    } else if (slot instanceof RecipeSlot) {
        RecipeSlot recipeSlot = (RecipeSlot) slot;
        if (recipeSlot.isVisible()) {
            if (button == 0) {
                fillFromStoredRecipe(recipeSlot.index, isShiftKeyDown());
            } else if (button == 1) {
                getTileEntity().removeStoredCraftingRecipe(recipeSlot.index);
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) InventoryDatabaseClient(crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient)

Example 62 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project EnderIO by SleepyTrousers.

the class HandlerSoulBound method addToPlayerInventory.

private static boolean addToPlayerInventory(EntityPlayer entityPlayer, ItemStack item) {
    if (item == null || entityPlayer == null) {
        return false;
    }
    if (item.getItem() instanceof ItemArmor) {
        ItemArmor arm = (ItemArmor) item.getItem();
        int index = arm.armorType.getIndex();
        if (Prep.isInvalid(entityPlayer.inventory.armorInventory.get(index))) {
            entityPlayer.inventory.armorInventory.set(index, item);
            Log.debug("Running addToPlayerInventory/armor logic for " + entityPlayer.getName() + ": " + item);
            return true;
        }
    }
    InventoryPlayer inv = entityPlayer.inventory;
    for (int i = 0; i < inv.mainInventory.size(); i++) {
        if (Prep.isInvalid(inv.mainInventory.get(i))) {
            inv.mainInventory.set(i, item.copy());
            Log.debug("Running addToPlayerInventory/main logic for " + entityPlayer.getName() + ": " + item);
            return true;
        }
    }
    Log.debug("Running addToPlayerInventory/fail logic for " + entityPlayer.getName() + ": " + item);
    return false;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemArmor(net.minecraft.item.ItemArmor)

Example 63 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.

the class ItemListSlotWidget method insertHeldItemStack.

// returns true if something actually happened
private boolean insertHeldItemStack(int button, boolean isClient) {
    InventoryPlayer inventory = gui.entityPlayer.inventory;
    int amountToInsert = button == 1 ? 1 : Integer.MAX_VALUE;
    if (!inventory.getItemStack().isEmpty()) {
        if (!isClient) {
            // on server, we lookup item list to see how much we can actually insert
            ItemStack heldItemStack = inventory.getItemStack();
            IItemList itemList = gridWidget.getItemList();
            int amountInserted = itemList.insertItem(new ItemStackKey(heldItemStack), Math.min(heldItemStack.getCount(), amountToInsert), false, InsertMode.LOWEST_PRIORITY);
            heldItemStack.shrink(amountInserted);
            uiAccess.sendHeldItemUpdate();
            gui.entityPlayer.openContainer.detectAndSendChanges();
            return amountInserted > 0;
        } else {
            // on client we assume we can insert full stack into the network
            inventory.getItemStack().shrink(amountToInsert);
            return true;
        }
    }
    return false;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IItemList(gregtech.common.inventory.IItemList) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 64 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.

the class ModularUIGui method renderItemStackOnMouse.

private void renderItemStackOnMouse(int mouseX, int mouseY) {
    InventoryPlayer inventory = this.mc.player.inventory;
    ItemStack itemStack = this.draggedStack.isEmpty() ? inventory.getItemStack() : this.draggedStack;
    if (!itemStack.isEmpty()) {
        int dragOffset = this.draggedStack.isEmpty() ? 8 : 16;
        if (!this.draggedStack.isEmpty() && this.isRightMouseClick) {
            itemStack = itemStack.copy();
            itemStack.setCount(MathHelper.ceil((float) itemStack.getCount() / 2.0F));
        } else if (this.dragSplitting && this.dragSplittingSlots.size() > 1) {
            itemStack = itemStack.copy();
            itemStack.setCount(this.dragSplittingRemnant);
        }
        this.drawItemStack(itemStack, mouseX - guiLeft - 8, mouseY - guiTop - dragOffset, null);
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 65 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project malmo by Microsoft.

the class ObservationFromCompassImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (player == null)
        return;
    InventoryPlayer inventory = player.inventory;
    boolean flag = false;
    for (int i = 0; i < 41; i++) if (inventory.getStackInSlot(i).getItem() instanceof ItemCompass)
        flag = true;
    // If there isn't a compass in the player's inventory, can't do anything
    if (!flag)
        json.addProperty("set", false);
    else {
        json.addProperty("set", true);
        // Get world spawn, which is what the compass points at
        BlockPos spawn = player.world.getSpawnPoint();
        json.addProperty("compass-x", spawn.getX());
        json.addProperty("compass-y", spawn.getY());
        json.addProperty("compass-z", spawn.getZ());
        BlockPos playerLoc = player.getPosition();
        json.addProperty("relative-x", spawn.getX() - playerLoc.getX());
        json.addProperty("relative-y", spawn.getY() - playerLoc.getY());
        json.addProperty("relative-z", spawn.getZ() - playerLoc.getZ());
        double dx = (playerLoc.getX() - spawn.getX());
        double dz = (playerLoc.getZ() - spawn.getZ());
        double idealYaw = ((Math.atan2(dz, dx) + Math.PI) * 180.0 / Math.PI);
        double playerYaw = player.rotationYaw;
        double difference = idealYaw - playerYaw;
        if (difference < 0)
            difference += 360;
        if (difference > 360)
            difference -= 360;
        json.addProperty("offset", difference);
        json.addProperty("normalized-offset", difference - 180);
        json.addProperty("distance", playerLoc.getDistance(spawn.getX(), spawn.getY(), spawn.getZ()));
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemCompass(net.minecraft.item.ItemCompass) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

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