Search in sources :

Example 66 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project minecolonies by Minecolonies.

the class WindowHutBuilder method pullResourcesFromHut.

/**
 * Retrieve resources from the building to display in GUI.
 */
private void pullResourcesFromHut() {
    final AbstractBuildingView newView = builder.getColony().getBuilding(builder.getID());
    if (newView instanceof BuildingBuilderView) {
        final BuildingBuilderView updatedView = (BuildingBuilderView) newView;
        final InventoryPlayer inventory = this.mc.player.inventory;
        final boolean isCreative = this.mc.player.capabilities.isCreativeMode;
        resources.clear();
        resources.addAll(updatedView.getResources().values());
        for (final BuildingBuilderResource resource : resources) {
            final int amountToSet;
            if (isCreative) {
                amountToSet = resource.getAmount();
            } else {
                amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), stack -> !ItemStackUtils.isEmpty(stack) && stack.isItemEqual(resource.getItemStack()));
            }
            resource.setPlayerAmount(amountToSet);
        }
        resources.sort(new BuildingBuilderResource.ResourceComparator());
    }
}
Also used : AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView) TransferItemsRequestMessage(com.minecolonies.coremod.network.messages.TransferItemsRequestMessage) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) SwitchView(com.minecolonies.blockout.views.SwitchView) Button(com.minecolonies.blockout.controls.Button) Pane(com.minecolonies.blockout.Pane) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemIcon(com.minecolonies.blockout.controls.ItemIcon) ScrollingList(com.minecolonies.blockout.views.ScrollingList) Color(com.minecolonies.blockout.Color) ArrayList(java.util.ArrayList) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) List(java.util.List) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) WindowConstants(com.minecolonies.api.util.constant.WindowConstants) MineColonies(com.minecolonies.coremod.MineColonies) InventoryUtils(com.minecolonies.api.util.InventoryUtils) MarkBuildingDirtyMessage(com.minecolonies.coremod.network.messages.MarkBuildingDirtyMessage) Label(com.minecolonies.blockout.controls.Label) Log(com.minecolonies.api.util.Log) NotNull(org.jetbrains.annotations.NotNull) Constants(com.minecolonies.api.util.constant.Constants) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) BuildingBuilderView(com.minecolonies.coremod.colony.buildings.views.BuildingBuilderView)

Example 67 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Tale-of-Kingdoms by Ivasik78.

the class GuiHunter method actionPerformed.

@Override
protected void actionPerformed(GuiButton button) {
    switch(button.id) {
        case 1:
            this.player.addChatMessage(!HunterHandler.INSTANCE.getHunter() ? new ChatComponentTranslation("gui.guildMaster.killMobs") : new ChatComponentTranslation("gui.guildMaster.discarded"));
            this.player.addChatMessage(new ChatComponentTranslation("gui.guildMaster.await"));
            this.initGui();
            break;
        case 2:
            if (1500 <= playerProvider.getGoldTotal()) {
                EntityLiving entityLiving = (EntityLiving) UltimateHelper.INSTANCE.getEntity("Hired", world);
                entityLiving.setLocationAndAngles(this.player.posX, this.player.posY, this.player.posZ, 0.0F, 0.0F);
                this.world.spawnEntityInWorld(entityLiving);
                playerProvider.decreaseGold(1500);
            } else {
                this.goldchecker = true;
            }
            break;
        case 3:
            this.mc.displayGuiScreen(null);
            this.goldchecker = false;
            break;
        case 4:
            InventoryPlayer inventoryPlayer = this.player.inventory;
            boolean entity = false;
            if (inventoryPlayer.hasItem(Item.getItemFromBlock(Blocks.log))) {
                for (ItemStack stack : inventoryPlayer.mainInventory) {
                    if (stack != null && stack.getItem() == Item.getItemFromBlock(Blocks.log)) {
                        if (stack.stackSize == stack.getMaxStackSize() && !entity) {
                            inventoryPlayer.setItemStack(null);
                            entity = true;
                        }
                    }
                }
            }
            if (!entity) {
                if (!this.world.isRemote) {
                    this.player.addChatMessage(new ChatComponentTranslation("gui.guildMaster.needMore"));
                }
            } else if (!this.world.isRemote) {
                this.player.addChatMessage(new ChatComponentTranslation("gui.guildMaster.fixed"));
            }
            break;
        case 5:
            IntStream.range(0, this.world.loadedEntityList.size()).mapToObj(var7 -> (Entity) this.world.loadedEntityList.get(var7)).filter(entity1 -> entity1 instanceof EntityHired).map(entity1 -> (EntityHired) entity1).forEach(var9 -> {
                var9.setDead();
                playerProvider.addGold(1000);
            });
            break;
    }
}
Also used : IntStream(java.util.stream.IntStream) Entity(net.minecraft.entity.Entity) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) Blocks(net.minecraft.init.Blocks) GuiPriceBar(kingdoms.api.gui.GuiPriceBar) GuiButton(net.minecraft.client.gui.GuiButton) Item(net.minecraft.item.Item) World(net.minecraft.world.World) HunterHandler(kingdoms.server.handlers.resources.HunterHandler) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) GuiScreenToK(kingdoms.api.gui.GuiScreenToK) EntityLiving(net.minecraft.entity.EntityLiving) EntityPlayer(net.minecraft.entity.player.EntityPlayer) UltimateHelper(kingdoms.server.handlers.UltimateHelper) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityHired(kingdoms.server.entities.EntityHired) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityHired(kingdoms.server.entities.EntityHired) ItemStack(net.minecraft.item.ItemStack)

Example 68 with InventoryPlayer

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

the class ControlSlot method getHelpTooltip.

@Override
public void getHelpTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) {
    final InventorySlot slot = this.getInventorySlot();
    if (slot != null) {
        tooltip.add(slot.getName());
        if (tooltipFlag.isAdvanced()) {
            Collection<EnumFacing> inputSides = slot.getInputSides();
            if (inputSides.size() > 0) {
                tooltip.add(TextFormatting.GRAY + I18N.localise(ModId.CORE, "gui.side.insert", MachineSide.asString(inputSides)));
            }
            Collection<EnumFacing> outputSides = slot.getOutputSides();
            if (outputSides.size() > 0) {
                tooltip.add(TextFormatting.GRAY + I18N.localise(ModId.CORE, "gui.side.extract", MachineSide.asString(outputSides)));
            }
            if (slot.isReadOnly()) {
                tooltip.add(TextFormatting.GRAY + I18N.localise(ModId.CORE, "gui.slot.pickup.only"));
            }
        }
    } else if (this.slot.inventory instanceof WindowInventory) {
        if (tooltipFlag.isAdvanced()) {
            final SlotValidator s = ((WindowInventory) this.slot.inventory).getValidator(this.slot.getSlotIndex());
            tooltip.add("Accepts: " + ((s == null) ? "Any Item" : s.getTooltip()));
        }
    } else if (this.slot.inventory instanceof InventoryPlayer) {
        if (tooltipFlag.isAdvanced()) {
            tooltip.add(I18N.localise(ModId.CORE, "gui.slot.player.inventory"));
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) WindowInventory(binnie.core.gui.minecraft.WindowInventory) EnumFacing(net.minecraft.util.EnumFacing) InventorySlot(binnie.core.machines.inventory.InventorySlot) SlotValidator(binnie.core.machines.inventory.SlotValidator)

Example 69 with InventoryPlayer

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

the class WindowGenesis method receiveGuiNBTOnServer.

@Override
public void receiveGuiNBTOnServer(final EntityPlayer player, final String name, final NBTTagCompound nbt) {
    super.receiveGuiNBTOnServer(player, name, nbt);
    if (name.equals(ACTION_GENESIS)) {
        ItemStack stack = new ItemStack(nbt);
        InventoryPlayer inventoryPlayer = player.inventory;
        ItemStack playerStack = inventoryPlayer.getItemStack();
        if (stack.isEmpty()) {
            return;
        }
        if (playerStack.isEmpty()) {
            inventoryPlayer.setItemStack(stack);
        } else if (playerStack.isItemEqual(stack) && ItemStack.areItemStackTagsEqual(playerStack, stack)) {
            final int fit = stack.getMaxStackSize() - (stack.getCount() + playerStack.getCount());
            if (fit >= 0) {
                stack.grow(playerStack.getCount());
                inventoryPlayer.setItemStack(stack);
            }
        }
        player.openContainer.detectAndSendChanges();
        if (player instanceof EntityPlayerMP) {
            ((EntityPlayerMP) player).updateHeldItem();
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 70 with InventoryPlayer

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

the class GuiCraftGUI method drawScreen.

@Override
public void drawScreen(final int mouseX, final int mouseY, final float partialTicks) {
    this.window.setMousePosition(mouseX - this.window.getPosition().xPos(), mouseY - this.window.getPosition().yPos());
    this.drawDefaultBackground();
    GlStateManager.disableRescaleNormal();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableLighting();
    GlStateManager.disableDepth();
    this.zLevel = 10.0f;
    // GuiScreen.itemRender.zLevel = this.zLevel;
    this.window.render(this.width, this.height);
    GlStateManager.pushMatrix();
    GlStateManager.enableRescaleNormal();
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
    final InventoryPlayer playerInventory = this.mc.player.inventory;
    this.draggedItem = playerInventory.getItemStack();
    if (!this.draggedItem.isEmpty()) {
        GlStateManager.translate(0, 0, 200);
        RenderUtil.drawItem(new Point(mouseX - 8, mouseY - 8), this.draggedItem, false);
    }
    RenderHelper.enableGUIStandardItemLighting();
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
    GlStateManager.disableLighting();
    GlStateManager.disableDepth();
    if (draggedItem.isEmpty()) {
        ITooltipFlag tooltipFlag = this.mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
        final MinecraftTooltip tooltip = new MinecraftTooltip();
        boolean helpMode = this.isHelpMode();
        if (helpMode || this.showBasicHelpTooltips()) {
            tooltip.setType(Tooltip.Type.HELP);
            ITooltipFlag helpTooltipFlag = helpMode ? ITooltipFlag.TooltipFlags.ADVANCED : tooltipFlag;
            if (!this.window.getHelpTooltip(tooltip, helpTooltipFlag)) {
                // fallback if there is no help tooltip
                this.window.getTooltip(tooltip, tooltipFlag);
            }
        } else {
            tooltip.setType(Tooltip.Type.STANDARD);
            this.window.getTooltip(tooltip, tooltipFlag);
        }
        if (tooltip.exists()) {
            this.renderTooltip(new Point(mouseX, mouseY), tooltip);
        }
    }
    this.zLevel = 0.0f;
    GlStateManager.enableLighting();
    GlStateManager.enableDepth();
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) IPoint(binnie.core.api.gui.IPoint) Point(binnie.core.gui.geometry.Point)

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