List of usage examples for net.minecraftforge.client.event GuiScreenEvent.MouseInputEvent.Pre getGui
public Screen getGui()
From source file:com.lothrazar.cyclicmagic.event.EventKeyInput.java
License:Open Source License
@SideOnly(Side.CLIENT) @SubscribeEvent(priority = EventPriority.HIGH) public void onMouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { if (event.getGui() == null || !(event.getGui() instanceof GuiContainer)) { return;/*from ww w . j a va2 s .c o m*/ } GuiContainer gui = (GuiContainer) event.getGui(); boolean rightClickDown = false; // event try { //if you press and hold the button, eventButton becomes -1 even when buttonDown(1) is true //so event button is on the mouseDown and mouseUp triggers rightClickDown = (Mouse.getEventButton() == 1) && Mouse.isButtonDown(1); } catch (Exception e) { //array out of bounds, crazy weird unexpected mouse //EXAMPLE: mod.chiselsandbits.bitbag.BagGui // so this fixes ithttps://github.com/PrinceOfAmber/Cyclic/issues/410 } // System.out.println(" Mouse.getEventButton() " + Mouse.getEventButton()); try { if (rightClickDown && gui.getSlotUnderMouse() != null) { int slot = gui.getSlotUnderMouse().slotNumber; if (gui.inventorySlots != null && slot < gui.inventorySlots.inventorySlots.size() && gui.inventorySlots.getSlot(slot) != null && !gui.inventorySlots.getSlot(slot).getStack().isEmpty()) { ItemStack maybeCharm = gui.inventorySlots.getSlot(slot).getStack(); if (maybeCharm.getItem() instanceof IHasClickToggle) { //example: is a charm or something ModCyclic.network.sendToServer(new PacketItemToggle(slot)); EntityPlayer player = ModCyclic.proxy.getClientPlayer(); UtilSound.playSound(player, SoundEvents.UI_BUTTON_CLICK); event.setCanceled(true); } } } } catch (Exception e) {//array out of bounds, or we are in a strange third party GUI that doesnt have slots like this //EXAMPLE: mod.chiselsandbits.bitbag.BagGui // so this fixes ithttps://github.com/PrinceOfAmber/Cyclic/issues/410 } }
From source file:cpw.mods.inventorysorter.KeyHandler.java
License:Open Source License
@SubscribeEvent(priority = EventPriority.LOWEST) public void onKey(GuiScreenEvent.MouseInputEvent.Pre evt) { Action action = Action.interpret(new KeyStates()); if (action != null && action.isActive() && evt.getGui() instanceof GuiContainer && !(evt.getGui() instanceof GuiContainerCreative)) { final GuiContainer guiContainer = (GuiContainer) evt.getGui(); Slot slot = guiContainer.getSlotUnderMouse(); if (slot == null) return; if (guiContainer.inventorySlots != null && guiContainer.inventorySlots.inventorySlots != null && guiContainer.inventorySlots.inventorySlots.contains(slot)) { InventorySorter.INSTANCE.log.log(Level.DEBUG, "Sending action {} slot {}", action, slot.slotNumber); InventorySorter.INSTANCE.channel.sendToServer(action.message(slot)); evt.setCanceled(true);//from ww w.j a v a 2s. c om } } }
From source file:vazkii.quark.management.feature.FavoriteItems.java
License:Creative Commons License
@SubscribeEvent(priority = EventPriority.HIGHEST) @SideOnly(Side.CLIENT)/*from w w w. j av a 2s . c om*/ public void mouseEvent(GuiScreenEvent.MouseInputEvent.Pre event) { boolean wasMouseDown = mouseDown; mouseDown = Mouse.isButtonDown(1); boolean click = mouseDown && !wasMouseDown; if (GuiScreen.isAltKeyDown() && click && event.getGui() instanceof GuiContainer) { GuiContainer gui = (GuiContainer) event.getGui(); Slot slot = gui.getSlotUnderMouse(); if (slot != null) { IInventory inv = slot.inventory; if (inv instanceof InventoryPlayer) { int index = slot.getSlotIndex(); if (Minecraft.getMinecraft().player.capabilities.isCreativeMode && index >= 36) index -= 36; // Creative mode messes with the indexes for some reason if (index < ((InventoryPlayer) inv).mainInventory.size()) { NetworkHandler.INSTANCE.sendToServer(new MessageFavoriteItem(index)); event.setCanceled(true); } } } } }