net.minecraft.client.gui.inventory.GuiInventory Java Examples

The following examples show how to use net.minecraft.client.gui.inventory.GuiInventory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HotBarRefillModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onWalkingUpdate (EventUpdateWalkingPlayer event) {
    if (this.timer.passed(this.delay.getValue())) {
        if (event.getStage() == EventStageable.EventStage.PRE) {
            Minecraft mc = Minecraft.getMinecraft();
            
            if (mc.currentScreen instanceof GuiInventory) {
                return;
            }

            int toRefill = getRefillable(mc.player);
            if (toRefill != -1) {
                refillHotbarSlot(mc, toRefill);
            }
        }

        timer.reset();
    }
}
 
Example #2
Source File: GuiEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onGuiOpenEvent(GuiOpenEvent event)
{
    // Reset the scrolling modifier when the player opens a GUI.
    // Otherwise the key up event will get eaten and our scrolling mode will get stuck on
    // until the player sneaks again.
    // FIXME Apparently there are key input events for GUI screens in 1.8,
    // so this probably can be removed then.
    InputEventHandler.resetModifiers();

    // Opening the player's Inventory GUI
    if (event.getGui() != null && event.getGui().getClass() == GuiInventory.class)
    {
        EntityPlayer player = FMLClientHandler.instance().getClientPlayerEntity();

        if (this.handyBagShouldOpen && player != null && ItemHandyBag.getOpenableBag(player).isEmpty() == false)
        {
            if (event.isCancelable())
            {
                event.setCanceled(true);
            }

            PacketHandler.INSTANCE.sendToServer(new MessageOpenGui(player.dimension, ReferenceGuiIds.GUI_ID_HANDY_BAG));
        }
    }
}
 
Example #3
Source File: GuiInventoryTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	if(player.getEntityData().hasKey("craftingTable"))
		Core.bindTexture(UPPER_TEXTURE);
	else
		Core.bindTexture(UPPER_TEXTURE_2X2);
	int k = this.guiLeft;
	int l = this.guiTop;
	this.drawTexturedModalRect(k, l, 0, 0, this.xSize, 102);

	//Draw the player avatar
	GuiInventory.drawEntityOnScreen(k + 51, l + 75, 30, k + 51 - this.xSizeLow, l + 75 - 50 - this.ySizeLow, this.mc.player);

	PlayerInventory.drawInventory(this, width, height, ySize - PlayerInventory.invYSize);
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
 
Example #4
Source File: PlayerDisplay.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void draw(int x, double y, boolean config) {
    GlStateManager.pushMatrix();
    GlStateManager.color(1, 1, 1);

    GlStateManager.translate(x, y, 0);
    RenderHelper.enableStandardItemLighting();
    GlStateManager.enableAlpha();

    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.enableAlpha();
    GlStateManager.enableDepth();

    GlStateManager.rotate(30, 0, 1.0F, 0);
    GuiInventory.drawEntityOnScreen(0, 100, 50, 0, 0, Minecraft.getMinecraft().thePlayer);
    GlStateManager.depthFunc(GL11.GL_LEQUAL);
    GlStateManager.resetColor();
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.disableDepth();
    GlStateManager.popMatrix();
}
 
Example #5
Source File: AutoCraftModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Minecraft mc = Minecraft.getMinecraft();

        if (this.recipe.getValue().length() > 0 && this.timer.passed(this.delay.getValue())) {
            if (mc.currentScreen == null || mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiCrafting) {
                mc.player.connection.sendPacket(new CPacketPlaceRecipe(mc.player.openContainer.windowId, CraftingManager.getRecipe(new ResourceLocation(this.recipe.getValue().toLowerCase())), true));

                mc.playerController.windowClick(mc.player.openContainer.windowId, 0, 0, this.drop.getValue() ? ClickType.THROW : ClickType.QUICK_MOVE, mc.player);
                mc.playerController.updateController();
            }

            this.timer.reset();
        }
    }
}
 
Example #6
Source File: QuickCraftModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onReceivePacket (EventReceivePacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof SPacketSetSlot) {
            // Check if this packet updates the recipe result and if the result is not empty
            if (((SPacketSetSlot) event.getPacket()).getSlot() == 0 && ((SPacketSetSlot) event.getPacket()).getStack().getItem() != Items.AIR) {
                Minecraft mc = Minecraft.getMinecraft();

                if (mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiCrafting) {
                    mc.playerController.windowClick(mc.player.openContainer.windowId, 0, 0, ClickType.QUICK_MOVE, mc.player);
                    mc.playerController.updateController();
                }
            }
        }
    }
}
 
Example #7
Source File: AutoTotemModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Minecraft mc = Minecraft.getMinecraft();

        if(mc.currentScreen == null || mc.currentScreen instanceof GuiInventory) {
            if(mc.player.getHealth() <= this.health.getValue()) {
                final ItemStack offHand = mc.player.getHeldItemOffhand();

                if (offHand.getItem() == Items.TOTEM_OF_UNDYING) {
                    return;
                }

                final int slot = this.getItemSlot(Items.TOTEM_OF_UNDYING);

                if(slot != -1) {
                    mc.playerController.windowClick(mc.player.inventoryContainer.windowId, slot, 0, ClickType.PICKUP, mc.player);
                    mc.playerController.windowClick(mc.player.inventoryContainer.windowId, 45, 0, ClickType.PICKUP, mc.player);
                    mc.playerController.windowClick(mc.player.inventoryContainer.windowId, slot, 0, ClickType.PICKUP, mc.player);
                    mc.playerController.updateController();
                }
            }
        }
    }
}
 
Example #8
Source File: AutoArmor.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shift+Left clicks the specified item
 *
 * @param item        Slot of the item to click
 * @param isArmorSlot
 * @return True if it is unable to move the item
 */
private boolean move(int item, boolean isArmorSlot) {
    if (!isArmorSlot && item < 9 && hotbarValue.get() && !(mc.currentScreen instanceof GuiInventory)) {
        mc.getNetHandler().addToSendQueue(new C09PacketHeldItemChange(item));
        mc.getNetHandler().addToSendQueue(new C08PacketPlayerBlockPlacement(mc.thePlayer.inventoryContainer.getSlot(item).getStack()));
        mc.getNetHandler().addToSendQueue(new C09PacketHeldItemChange(mc.thePlayer.inventory.currentItem));

        delay = TimeUtils.randomDelay(minDelayValue.get(), maxDelayValue.get());

        return true;
    } else if (!(noMoveValue.get() && MovementUtils.isMoving()) && (!invOpenValue.get() || mc.currentScreen instanceof GuiInventory) && item != -1) {
        final boolean openInventory = simulateInventory.get() && !(mc.currentScreen instanceof GuiInventory);

        if (openInventory)
            mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT));

        mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, isArmorSlot ? item : (item < 9 ? item + 36 : item), 0, 1, mc.thePlayer);

        delay = TimeUtils.randomDelay(minDelayValue.get(), maxDelayValue.get());

        if (openInventory)
            mc.getNetHandler().addToSendQueue(new C0DPacketCloseWindow());

        return true;
    }

    return false;
}
 
Example #9
Source File: VanillaEnhancementsHud.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
@InvokeEvent
public void onRenderArmor(GuiDrawScreenEvent e) {
    if ((Settings.ARMOR_PROT_POTENTIONAL || Settings.ARMOR_PROJ_POTENTIONAL) && (e.getScreen() instanceof GuiInventory || e.getScreen() instanceof GuiContainerCreative)) {
        ScaledResolution res = new ScaledResolution(mc);
        String message = getArmorString();
        mc.currentScreen.drawString(mc.fontRendererObj, message, 10, res.getScaledHeight() - 16, -1);
    }
}
 
Example #10
Source File: ExtraInventory.java    From ForgeHax with MIT License 5 votes vote down vote up
private GuiInventory createGuiWrapper(GuiInventory gui) {
  try {
    GuiInventoryWrapper wrapper = new GuiInventoryWrapper();
    ReflectionHelper.copyOf(gui, wrapper); // copy all fields from the provided gui to the wrapper
    return wrapper;
  } catch (NoSuchFieldException | IllegalAccessException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example #11
Source File: ExtraInventory.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onUpdate(LocalPlayerUpdateEvent event) {
  if (auto_store.get() && (!clickTimer.isStarted() || clickTimer.hasTimeElapsed(delay.get()))) {
    // start a click task if one should be
    if (nextClickTask == null) {
      InventoryPlayer inventory = LocalPlayerInventory.getInventory();
      // check if inventory is full
      if (inventory.getFirstEmptyStack() == -1) { // TODO: check only top part of inventory
        // find available slot
        EasyIndex next = getAvailableIndex();
        if (!next.isNone()) {
          // find best slot to replace
          Slot best = getBestSlotCandidate();
          if (best != null) {
            // open and close the gui to create open instance
            
            if (openedGui == null) {
              MC.displayGuiScreen(new GuiInventory(getLocalPlayer()));
              MC.displayGuiScreen(null);
            }
            
            nextClickTask = getSlotSettingTask(best, next);
          }
        }
      }
    }
    
    if (nextClickTask != null) {
      try {
        // run the task
        nextClickTask = nextClickTask.run();
      } catch (ExecutionFailure e) {
        nextClickTask = null;
      } finally {
        // start timer (this maybe done twice due to the packet hook, but that is okay)
        clickTimer.start();
      }
    }
  }
}
 
Example #12
Source File: ExtraInventory.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onGuiOpen(GuiOpenEvent event) {
  if (guiCloseGuard) {
    // do not close the gui when this mod executes closeWindow()
    event.setCanceled(true);
  } else if (event.getGui() instanceof GuiInventory) {
    // create a wrapper and replace the gui
    event.setGui(openedGui = createGuiWrapper((GuiInventory) event.getGui()));
    // server doesn't need to be informed the gui has been closed
    guiNeedsClose.set(false);
  }
}
 
Example #13
Source File: ItemHandUpgrade.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void handleOpenInv(GuiOpenEvent event)
{
	if (Minecraft.getMinecraft() != null && Minecraft.getMinecraft().thePlayer != null && event.getGui() != null && event.getGui().getClass() == GuiInventory.class && !Minecraft.getMinecraft().thePlayer.isCreative())
	{
		if (CyberwareAPI.isCyberwareInstalled(Minecraft.getMinecraft().thePlayer, new ItemStack(this, 1, 0)))
		{
			event.setCanceled(true);

			Minecraft.getMinecraft().thePlayer.openGui(Cyberware.INSTANCE, 1, Minecraft.getMinecraft().thePlayer.worldObj, 0, 0, 0);
			CyberwarePacketHandler.INSTANCE.sendToServer(new GuiPacket(1, 0, 0, 0));
		}
	}
}
 
Example #14
Source File: NEIClientPacketHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, Minecraft mc, INetHandlerPlayClient netHandler) {
    switch (packet.getType()) {
        case 1:
            handleServerSideCheck(packet.readUByte(), packet.readString(), mc.world);
            break;
        case 10:
            handleLoginState(packet);
            break;
        case 11:
            handleActionDisableStateChange(packet);
            break;
        case 12:
            handleActionEnabled(packet);
            break;
        case 13:
            MagnetModeHandler.INSTANCE.trackMagnetItem(packet.readInt(), mc.world);
            break;
        case 14:
            handleGameMode(mc, packet.readUByte());
            break;
        case 21:
            ClientUtils.openSMPGui(packet.readUByte(), new GuiEnchantmentModifier(mc.player.inventory, mc.world));
            break;
        case 23:
            if (packet.readBoolean()) {
                ClientUtils.openSMPGui(packet.readUByte(), new GuiExtendedCreativeInv(new ContainerCreativeInv(mc.player, new ExtendedCreativeInv(null, Side.CLIENT))));
            } else {
                mc.displayGuiScreen(new GuiInventory(mc.player));
            }
            break;
        case 24:
            ClientUtils.openSMPGui(packet.readUByte(), new GuiPotionCreator(mc.player.inventory));
            break;
    }
}
 
Example #15
Source File: NEICPH.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, Minecraft mc, INetHandlerPlayClient netHandler) {
    switch (packet.getType()) {
        case 1:
            handleSMPCheck(packet.readUByte(), packet.readString(), mc.theWorld);
            break;
        case 10:
            handleLoginState(packet);
            break;
        case 11:
            handleActionDisabled(packet);
            break;
        case 12:
            handleActionEnabled(packet);
            break;
        case 13:
            ClientHandler.instance().addSMPMagneticItem(packet.readInt(), mc.theWorld);
            break;
        case 14:
            handleGamemode(mc, packet.readUByte());
            break;
        case 21:
            ClientUtils.openSMPGui(packet.readUByte(), new GuiEnchantmentModifier(mc.thePlayer.inventory, mc.theWorld));
            break;
        case 23:
            if (packet.readBoolean())
                ClientUtils.openSMPGui(packet.readUByte(), new GuiExtendedCreativeInv(new ContainerCreativeInv(mc.thePlayer, new ExtendedCreativeInv(null, Side.CLIENT))));
            else
                mc.displayGuiScreen(new GuiInventory(mc.thePlayer));
            break;
        case 24:
            ClientUtils.openSMPGui(packet.readUByte(), new GuiPotionCreator(mc.thePlayer.inventory));
            break;
    }
}
 
Example #16
Source File: KeepContainer.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@EventTarget
public void onGui(final ScreenEvent event) {
    if(event.getGuiScreen() instanceof GuiContainer && !(event.getGuiScreen() instanceof GuiInventory))
        container = (GuiContainer) event.getGuiScreen();
}
 
Example #17
Source File: ParticleOverlay.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void render(int mouseX, int mouseY, int guiLeft, int guiTop, int guiRight, int guiBottom) {
    if (!purchased()) return;
    try {
        float step = (float) (0.01 * (Settings.MAX_PARTICLES / 100));
        Mode m = getMode();
        if (m == Mode.OFF) return;
        if (!Settings.PARTICLES_INV && Minecraft.getMinecraft().currentScreen instanceof GuiInventory) {
            return;
        }

        last = System.currentTimeMillis();

        for (Particle particle : particles) {
            double w = 1;
            float v1 = ((float) ResolutionUtil.current().getScaledWidth_double()) * particle.x;
            float v2 = ((float) ResolutionUtil.current().getScaledHeight_double()) * particle.y;
            double mouseDis = Math.pow(v1 - mouseX, 2) + Math.pow(v2 - mouseY, 2);
            int i = ResolutionUtil.current().getScaledWidth() / 12;

            if (mouseDis < Math.pow(i, 2)) {
                float xVec = Math.min(500F, (float) i / (mouseX - v1));
                float yVec = Math.min(500F, (float) i / (mouseY - v2));
                v1 -= xVec;
                v2 -= yVec;
                particle.regenerateVector();
            }

            particle.x = v1 / (float) ResolutionUtil.current().getScaledWidth_double();
            particle.y = v2 / (float) ResolutionUtil.current().getScaledHeight_double();

            for (Particle particle1 : particles) {
                double v = particle.distSqTo(particle1);
                //Threshold for line
                if (v < 0.02) {
                    double lineStrength = Math.min(10000.0D, 1.0D / v) / 100D;
                    float x2 = ((float) ResolutionUtil.current().getScaledWidth_double()) * particle1.x;
                    float y2 = ((float) ResolutionUtil.current().getScaledHeight_double()) * particle1.y;
                    double alpha = 100 + ((0.02 / 155) * v);

                    boolean flag = false;
                    if (((v1 >= guiLeft && v1 <= guiRight) || (x2 >= guiLeft && x2 <= guiRight))
                        && ((v2 >= guiTop && v2 <= guiBottom) || (y2 >= guiTop && y2 <= guiBottom))) {
                        if (!Settings.PARTICLES_INV) continue;
                        alpha /= 4;
                        flag = true;
                    }


                    int color = Color.HSBtoRGB(h, 0.8F, 0.8F);
                    Color eee = new Color(color);
                    eee = new Color(eee.getRed(), eee.getBlue(), eee.getGreen(), flag ? 255 / 4 : 255);

                    switch (m) {
                        case PLAIN_1:
                            RenderUtils.drawLine(v1, v2, x2, y2, (float) lineStrength, new Color(255, 255, 255, (int) alpha).getRGB());
                            break;
                        case PLAIN_2:
                            RenderUtils.drawLine(v1, v2, x2, y2, 1F, new Color(255, 255, 255, (int) alpha).getRGB());
                            break;
                        case CHROMA_1:
                            RenderUtils.drawLine(v1, v2, x2, y2, (float) lineStrength, eee.getRGB());
                            break;
                        case CHROMA_2:
                            RenderUtils.drawLine(v1, v2, x2, y2, 1F, eee.getRGB());
                            break;
                    }

                    w += lineStrength;
                }
            }

            if (h >= 1.0F) h = 0.0F;
            h += step;
            if (!Settings.PARTICLES_INV) continue;
            w = Math.sqrt(w) / 10D;
            Gui.drawRect((int) v1, (int) v2, (int) (v1 + w), (int) (v2 + w), Color.WHITE.getRGB());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #18
Source File: ContainerManager.java    From CraftingKeys with MIT License 4 votes vote down vote up
/**
 * Handles what to do with NumKey-Inputs while holding a item.
 *
 * @param currentHoveredSlot slot where the mouse is right now
 */
void handleNumKey(Slot currentHoveredSlot) {

    // hotbar-slots are always the last 9 slots of the currently opened inventory
    int hotbarStartIndex = Util.client.player.openContainer.getInventory().size() - 9 - 1;

    if (Util.client.currentScreen instanceof GuiInventory) {
        hotbarStartIndex -= 1;
    }

    int inputdelta;
    KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar;

    if (Keyboard.isKeyDown(hotbar[0].getKeyCode())) {
        inputdelta = 1;
    } else if (Keyboard.isKeyDown(hotbar[1].getKeyCode())) {
        inputdelta = 2;
    } else if (Keyboard.isKeyDown(hotbar[2].getKeyCode())) {
        inputdelta = 3;
    } else if (Keyboard.isKeyDown(hotbar[3].getKeyCode())) {
        inputdelta = 4;
    } else if (Keyboard.isKeyDown(hotbar[4].getKeyCode())) {
        inputdelta = 5;
    } else if (Keyboard.isKeyDown(hotbar[5].getKeyCode())) {
        inputdelta = 6;
    } else if (Keyboard.isKeyDown(hotbar[6].getKeyCode())) {
        inputdelta = 7;
    } else if (Keyboard.isKeyDown(hotbar[7].getKeyCode())) {
        inputdelta = 8;
    } else if (Keyboard.isKeyDown(hotbar[8].getKeyCode())) {
        inputdelta = 9;
    } else {
        return;
    }

    // If no stack is held and a num-key is pressed, get the output by interaction, but only
    // if there could not be meant another stack at mouse position. cool logic!
    if (!Util.isHoldingStack()) {

        if (currentHoveredSlot == null || !currentHoveredSlot.getHasStack()) {
            Logger.info("handleNumKey()", "Trying output to hotbar speedup.");
            onInteractionKeyPressed();
        }
    }

    // If held, move!
    if (Util.isHoldingStack()) {

        leftClick(hotbarStartIndex + inputdelta);
        Logger.info("handleNumKey()", "Moved to hotbar slot " + inputdelta + ".");

        moveStackToInventory(-1);

        // Handle Minecraft handling. Ah...
        while (Keyboard.next()) {
            Logger.info("handleNumKey()", "The cake is a lie!");
        }
    }


}
 
Example #19
Source File: GuiHandler.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void openGuiHandler(GuiOpenEvent event)
{
	if(event.getGui() instanceof GuiInventory && !(event.getGui() instanceof GuiInventoryTFC))
		event.setGui(new GuiInventoryTFC(Minecraft.getMinecraft().player));
}