org.lwjgl.input.Mouse Java Examples
The following examples show how to use
org.lwjgl.input.Mouse.
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: Utils.java From Hyperium with GNU Lesser General Public License v3.0 | 7 votes |
public void setCursor(ResourceLocation cursor) { try { BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(cursor).getInputStream()); int w = image.getWidth(); int h = image.getHeight(); int[] pixels = new int[(w * h)]; image.getRGB(0, 0, w, h, pixels, 0, w); ByteBuffer buffer = BufferUtils.createByteBuffer(w * h * 4); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int pixel = pixels[(h - 1 - y) * w + x]; buffer.put((byte) (pixel & 0xFF)); buffer.put((byte) (pixel >> 8 & 0xFF)); buffer.put((byte) (pixel >> 16 & 0xFF)); buffer.put((byte) (pixel >> 24 & 0xFF)); } } buffer.flip(); Mouse.setNativeCursor(new Cursor(w, h, 0, h - 1, 1, buffer.asIntBuffer(), null)); } catch (Exception ignored) { } }
Example #2
Source File: CPSKey.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void renderKey(int x, int y) { int yOffset = this.yOffset; if (!mod.getSettings().isShowingMouseButtons()) yOffset -= 24; if (!mod.getSettings().isShowingSpacebar()) yOffset -= 18; if (!mod.getSettings().isShowingSneak()) yOffset -= 18; if (!mod.getSettings().isShowingWASD()) yOffset -= 48; Mouse.poll(); int textColor = getColor(); if (mod.getSettings().isKeyBackgroundEnabled()) { Gui.drawRect(x + xOffset, y + yOffset, x + xOffset + 70, y + yOffset + 16, new Color(mod.getSettings().getKeyBackgroundRed(), mod.getSettings().getKeyBackgroundGreen(), mod.getSettings().getKeyBackgroundBlue(), mod.getSettings().getKeyBackgroundOpacity()).getRGB()); } String name = (mod.getSettings().isLeftClick() ? getLeftCPS() : getRightCPS()) + " CPS"; if (mod.getSettings().isChroma()) { drawChromaString(name, ((x + (xOffset + 70) / 2) - mc.fontRendererObj.getStringWidth(name) / 2), y + (yOffset + 4), 1.0F); } else { drawCenteredString(name, x + (xOffset + 70) / 2, y + (yOffset + 4), textColor); } }
Example #3
Source File: GuiEnderUtilities.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handleMouseInput() throws IOException { int dWheel = Mouse.getEventDWheel(); if (dWheel != 0) { int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth; int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; for (int i = 0; i < this.buttonList.size(); i++) { GuiButton button = this.buttonList.get(i); if (button.mousePressed(this.mc, mouseX, mouseY)) { this.actionPerformedWithButton(button, 10 + dWheel / 120); break; } } } else { super.handleMouseInput(); } }
Example #4
Source File: Game.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
/** * Gets the input. * * @return the input */ public static void getInput() { Keyboard.poll(); keys.clear(); while(Keyboard.next()) { KeyboardEvent ke = new KeyboardEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(), Keyboard.isRepeatEvent(), Keyboard.getEventKeyState(), KeyboardEvent.generateModifiers()); keys.add(ke); } Mouse.poll(); mouseEvents.clear(); while(Mouse.next()) { MouseEvent me = new MouseEvent( Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventDWheel(), Mouse.getEventButton(), Mouse.getEventButtonState()); mouseEvents.add(me); } }
Example #5
Source File: CarpenterOpener.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void onMouse(MouseEvent event) { try { MovingObjectPosition position = Wrapper.INSTANCE.mc().objectMouseOver; if (position.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && Mouse.isButtonDown(1)) { if (event.isCancelable()) { event.setCanceled(true); } ByteBuf buf = Unpooled.buffer(0); buf.writeInt(0); buf.writeInt(position.blockX); buf.writeInt(position.blockY); buf.writeInt(position.blockZ); buf.writeInt(position.sideHit); C17PacketCustomPayload packet = new C17PacketCustomPayload("CarpentersBlocks", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); } } catch (Exception e) { } }
Example #6
Source File: SlowlyStyle.java From LiquidBounce with GNU General Public License v3.0 | 6 votes |
public static float drawSlider(final float value, final float min, final float max, final int x, final int y, final int width, final int mouseX, final int mouseY, final Color color) { final float displayValue = Math.max(min, Math.min(value, max)); final float sliderValue = (float) x + (float) width * (displayValue - min) / (max - min); RenderUtils.drawRect(x, y, x + width, y + 2, Integer.MAX_VALUE); RenderUtils.drawRect(x, y, sliderValue, y + 2, color); RenderUtils.drawFilledCircle((int) sliderValue, y + 1, 3, color); if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 3 && Mouse.isButtonDown(0)) { double i = MathHelper.clamp_double(((double) mouseX - (double) x) / ((double) width - 3), 0, 1); BigDecimal bigDecimal = new BigDecimal(Double.toString((min + (max - min) * i))); bigDecimal = bigDecimal.setScale(2, 4); return bigDecimal.floatValue(); } return value; }
Example #7
Source File: AdvancedTextWidget.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@SideOnly(Side.CLIENT) private boolean handleCustomComponentClick(ITextComponent textComponent) { Style style = textComponent.getStyle(); if (style.getClickEvent() != null) { ClickEvent clickEvent = style.getClickEvent(); String componentText = clickEvent.getValue(); if (clickEvent.getAction() == Action.OPEN_URL && componentText.startsWith("@!")) { String rawText = componentText.substring(2); ClickData clickData = new ClickData(Mouse.getEventButton(), isShiftDown(), isCtrlDown()); writeClientAction(1, buf -> { clickData.writeToBuf(buf); buf.writeString(rawText); }); return true; } } return false; }
Example #8
Source File: SpaceFire.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void onMouse(MouseEvent event) { try { MovingObjectPosition position = Wrapper.INSTANCE.mc().objectMouseOver; if (position.entityHit instanceof EntityLivingBase && Mouse.isButtonDown(0)) { Object packetPipeLine = Class.forName("micdoodle8.mods.galacticraft.core.GalacticraftCore").getField("packetPipeline").get(null); Method sendMethod = packetPipeLine.getClass().getMethod("sendToServer", Class.forName("micdoodle8.mods.galacticraft.core.network.IPacket")); Object packetObj = Class.forName("micdoodle8.mods.galacticraft.core.network.PacketSimple").getConstructor(new Class[]{Class.forName("micdoodle8.mods.galacticraft.core.network.PacketSimple$EnumSimplePacket"), Object[].class}).newInstance(Class.forName("micdoodle8.mods.galacticraft.core.network.PacketSimple$EnumSimplePacket").getMethod("valueOf", String.class).invoke(null, "S_SET_ENTITY_FIRE"), new Object[]{position.entityHit.getEntityId()}); sendMethod.invoke(packetPipeLine, packetObj); if (event.isCancelable()) { event.setCanceled(true); } } } catch (Exception e) { } }
Example #9
Source File: ExtendedDestroyer.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void onMouse(MouseEvent event) { try { MovingObjectPosition position = Wrapper.INSTANCE.mc().objectMouseOver; boolean nowState = Mouse.isButtonDown(0); if (position.sideHit != -1 && nowState && !prevState) { ByteBuf buf = Unpooled.buffer(0); buf.writeByte(14); buf.writeInt(position.blockX); buf.writeInt(position.blockY); buf.writeInt(position.blockZ); C17PacketCustomPayload packet = new C17PacketCustomPayload("cfm", buf); Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet); } prevState = nowState; } catch (Exception ignored) { } }
Example #10
Source File: ShowContainer.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void onMouse(MouseEvent event) { try { boolean nowState = Mouse.isButtonDown(1); MovingObjectPosition position = Wrapper.INSTANCE.mc().objectMouseOver; if (position.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && !prevState && nowState) { TileEntity tileEntity = Wrapper.INSTANCE.world().getTileEntity(position.blockX, position.blockY, position.blockZ); if (tileEntity instanceof IInventory) { ItemStack[] stacks = new ItemStack[0]; Wrapper.INSTANCE.mc().displayGuiScreen(new ShowContainerGui(new ShowContainerContainer(stacks, tileEntity.getClass().getSimpleName()))); if (event.isCancelable()) { event.setCanceled(true); } } else { InteropUtils.log("Not a container", this); } } prevState = nowState; } catch (Exception ignored) { } }
Example #11
Source File: GuiWindowMod.java From ForgeHax with MIT License | 6 votes |
public void handleMouseInput() throws IOException { int i = Mouse.getEventDWheel(); i = MathHelper.clamp(i, -1, 1); buttonListOffset -= i * 10; if (buttonListOffset < 0) { buttonListOffset = 0; // dont scroll up if its already at the top } int lowestButtonY = (GuiButton.height + 1) * buttonList.size() + windowY; int lowestAllowedOffset = lowestButtonY - height - windowY + 3; if (lowestButtonY - buttonListOffset < bottomY) { buttonListOffset = lowestAllowedOffset; } }
Example #12
Source File: XrayModChooserGui.java From MinecraftX-RAY with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void handleMouseInput() throws IOException { super.handleMouseInput(); int mouseScrollWheelStatus = Mouse.getEventDWheel(); int mouseButtonStatus = Mouse.getEventButton(); boolean mouseButtonState = Mouse.getEventButtonState(); if ((mouseScrollWheelStatus > 0) && (this.listPos > 0)) { --this.listPos; } else if ((mouseScrollWheelStatus < 0) && (this.listPos < this.idList.size() - 1)) { ++this.listPos; } if ((mouseButtonState) && (mouseButtonStatus != -1)) { if ((this.invisibleIdList.indexOf(this.idList.get(this.listPos)) >= 0)) { this.invisibleIdList.remove(this.idList.get(this.listPos)); } else { this.invisibleIdList.add(this.idList.get(this.listPos)); } } }
Example #13
Source File: MalmoModClient.java From malmo with MIT License | 6 votes |
@Override public void mouseXYChange() { if (this.isOverriding) { this.deltaX = 0; this.deltaY = 0; if (Mouse.isGrabbed()) Mouse.setGrabbed(false); } else { super.mouseXYChange(); if (this.observer != null) this.observer.onXYZChange(this.deltaX, this.deltaY, Mouse.getDWheel()); } }
Example #14
Source File: FakeDestroy.java From ehacks-pro with GNU General Public License v3.0 | 6 votes |
@Override public void onMouse(MouseEvent event) { try { boolean nowState = Mouse.isButtonDown(0); MovingObjectPosition position = Wrapper.INSTANCE.mc().objectMouseOver; if (position.sideHit != -1 && !prevState && nowState) { removedBlocks.add(new BlockInfo(new int[]{position.blockX, position.blockY, position.blockZ}, Wrapper.INSTANCE.world().getBlock(position.blockX, position.blockY, position.blockZ), Wrapper.INSTANCE.world().getBlockMetadata(position.blockX, position.blockY, position.blockZ))); Wrapper.INSTANCE.world().setBlockToAir(position.blockX, position.blockY, position.blockZ); if (event.isCancelable()) { event.setCanceled(true); } } prevState = nowState; } catch (Exception ignored) { } }
Example #15
Source File: GuiScreenEditKeys.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void handleInput() throws IOException { if (listeningForNewKey) { if (Mouse.next()) { int button = Mouse.getEventButton(); if (Mouse.isButtonDown(button)) { selected.getKey().setKey(button - 100); listeningForNewKey = false; changeKey.displayString = "Change key"; return; } } if (Keyboard.next()) { int key = Keyboard.getEventKey(); if (Keyboard.isKeyDown(key)) { selected.getKey().setKey(key); listeningForNewKey = false; changeKey.displayString = "Change key"; return; } } } super.handleInput(); }
Example #16
Source File: LwjglCanvas.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void pauseCanvas(){ if (Mouse.isCreated()){ if (Mouse.isGrabbed()){ Mouse.setGrabbed(false); mouseWasGrabbed = true; } mouseWasCreated = true; Mouse.destroy(); } if (Keyboard.isCreated()){ keyboardWasCreated = true; Keyboard.destroy(); } renderable.set(false); destroyContext(); }
Example #17
Source File: GuiEngineeringTable.java From Cyberware with MIT License | 6 votes |
public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (this.visible) { float trans = 0.4F; boolean down = Mouse.isButtonDown(0); boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; mc.getTextureManager().bindTexture(ENGINEERING_GUI_TEXTURES); int i = 39; int j = 34; if (down && flag) { i = 0; j = 166; } this.drawTexturedModalRect(this.xPosition, this.yPosition, i, j, 21, 21); } }
Example #18
Source File: DefaultController.java From Slyther with MIT License | 6 votes |
@Override public void update(SlytherClient client) { ClientSnake player = client.player; accelerating = Mouse.isButtonDown(0) || Mouse.isButtonDown(1); int mouseX = Mouse.getX() - (Display.getWidth() / 2); int mouseY = (Display.getHeight() - Mouse.getY()) - (Display.getHeight() / 2); if (mouseX != lastMouseX || mouseY != lastMouseY) { lastMouseX = mouseX; lastMouseY = mouseY; int dist = mouseX * mouseX + mouseY * mouseY; if (dist > 256) { targetAngle = (float) Math.atan2(mouseY, mouseX); player.eyeAngle = targetAngle; } else { targetAngle = player.wantedAngle; } } }
Example #19
Source File: LwjglMouseInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void setCursorVisible(boolean visible){ cursorVisible = visible; if (!context.isRenderable()) return; Mouse.setGrabbed(!visible); }
Example #20
Source File: PointerInput.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
public final static void setActiveCursor(Cursor cursor) { if (cursor != null && Mouse.isGrabbed()) { Mouse.setGrabbed(false); resetCursorPos(); } else if (cursor == null && !Mouse.isGrabbed()) { Mouse.setGrabbed(true); resetCursorPos(); } if (active_cursor != cursor) { doSetActiveCursor(cursor); } }
Example #21
Source File: MidClick.java From LiquidBounce with GNU General Public License v3.0 | 5 votes |
@EventTarget public void onRender(Render2DEvent event) { if(mc.currentScreen != null) return; if(!wasDown && Mouse.isButtonDown(2)) { final Entity entity = mc.objectMouseOver.entityHit; if(entity instanceof EntityPlayer) { final String playerName = ColorUtils.stripColor(entity.getName()); final FriendsConfig friendsConfig = LiquidBounce.fileManager.friendsConfig; if(!friendsConfig.isFriend(playerName)) { friendsConfig.addFriend(playerName); LiquidBounce.fileManager.saveConfig(friendsConfig); ClientUtils.displayChatMessage("§a§l" + playerName + "§c was added to your friends."); }else{ friendsConfig.removeFriend(playerName); LiquidBounce.fileManager.saveConfig(friendsConfig); ClientUtils.displayChatMessage("§a§l" + playerName + "§c was removed from your friends."); } }else ClientUtils.displayChatMessage("§c§lError: §aYou need to select a player."); } wasDown = Mouse.isButtonDown(2); }
Example #22
Source File: ModuleListComponent.java From seppuku with GNU General Public License v3.0 | 5 votes |
private void handleScrolling(int mouseX, int mouseY) { final boolean inside = mouseX >= this.getX() && mouseX <= this.getX() + this.getW() && mouseY >= this.getY() && mouseY <= this.getY() + this.getH(); if (inside && Mouse.hasWheel()) { this.scroll += -(Mouse.getDWheel() / 10); if (this.scroll < 0) { this.scroll = 0; } if (this.scroll > this.totalHeight - this.getH()) { this.scroll = this.totalHeight - (int) this.getH(); } } }
Example #23
Source File: GuiHyperiumCredits.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void handleMouseInput() throws IOException { super.handleMouseInput(); int i = Mouse.getEventDWheel(); if (i < 0 && offY > -240) offY -= 20; // todo: not hardcode this else if (i > 0 && offY < 0) offY += 20; }
Example #24
Source File: Camera.java From LowPolyWater with The Unlicense | 5 votes |
/** * Calculate the pitch and change the pitch if the user is moving the mouse * up or down with the LMB pressed. */ private void calculatePitch() { if (Mouse.isButtonDown(0)) { float pitchChange = Mouse.getDY() * PITCH_SENSITIVITY; pitch.increaseTarget(-pitchChange); clampPitch(); } pitch.update(1f / 60); }
Example #25
Source File: XRayAddGui.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
@Override public void handleMouseInput() { super.handleMouseInput(); int x = Mouse.getEventDWheel(); ArrayList blockstodraw = this.getItemStackList(); int xmax = blockstodraw.size() / 9; int xmin = 0; if (x < 0) { if (this.sliderpos < xmax) { ++this.sliderpos; } } else if (x > 0 && this.sliderpos > xmin) { --this.sliderpos; } }
Example #26
Source File: Gui2ndChat.java From The-5zig-Mod with MIT License | 5 votes |
@Override public boolean mouseClicked(int mouseX, int mouseY, int button) { try { return button == 0 && (clickChatComponent != null ? (Boolean) clickChatComponent.invoke(MinecraftFactory.getVars().getMinecraftScreen(), getChatComponent(Mouse.getX(), Mouse.getY())) : ((bgp) MinecraftFactory.getVars().getMinecraftScreen()).a(getChatComponent(Mouse.getX(), Mouse.getY()))); } catch (Exception e) { throw new RuntimeException(e); } }
Example #27
Source File: SignTextMod.java From ForgeHax with MIT License | 5 votes |
@SubscribeEvent public void onInput(MouseEvent event) { if (event.getButton() == 2 && Mouse.getEventButtonState()) { // on middle click RayTraceResult result = MC.player.rayTrace(999, 0); if (result == null) { return; } if (result.typeOfHit == RayTraceResult.Type.BLOCK) { TileEntity tileEntity = MC.world.getTileEntity(result.getBlockPos()); if (tileEntity instanceof TileEntitySign) { TileEntitySign sign = (TileEntitySign) tileEntity; int signTextLength = 0; // find the first line from the bottom that isn't empty for (int i = 3; i >= 0; i--) { if (!sign.signText[i].getUnformattedText().isEmpty()) { signTextLength = i + 1; break; } } if (signTextLength == 0) { return; // if the sign is empty don't do anything } String[] lines = new String[signTextLength]; for (int i = 0; i < signTextLength; i++) { lines[i] = sign.signText[i].getFormattedText().replace(TextFormatting.RESET.toString(), ""); } String fullText = String.join("\n", lines); Helper.printMessage("Copied sign"); setClipboardString(fullText); } } } }
Example #28
Source File: Gui2ndChat.java From The-5zig-Mod with MIT License | 5 votes |
@Override public boolean mouseClicked(int mouseX, int mouseY, int button) { try { return button == 0 && (clickChatComponent != null ? (Boolean) clickChatComponent.invoke(MinecraftFactory.getVars().getMinecraftScreen(), getChatComponent(Mouse.getX(), Mouse.getY())) : ((bew) MinecraftFactory.getVars().getMinecraftScreen()).a(getChatComponent(Mouse.getX(), Mouse.getY()))); } catch (Exception e) { throw new RuntimeException(e); } }
Example #29
Source File: Gui2ndChat.java From The-5zig-Mod with MIT License | 5 votes |
@Override public boolean mouseClicked(int mouseX, int mouseY, int button) { try { return button == 0 && (clickChatComponent != null ? (Boolean) clickChatComponent.invoke(MinecraftFactory.getVars().getMinecraftScreen(), getChatComponent(Mouse.getX(), Mouse.getY())) : ((axu) MinecraftFactory.getVars().getMinecraftScreen()).a(getChatComponent(Mouse.getX(), Mouse.getY()))); } catch (Exception e) { throw new RuntimeException(e); } }
Example #30
Source File: GuiListChat.java From The-5zig-Mod with MIT License | 5 votes |
/** * Handle Mouse Input */ @Override public void handleMouseInput() { super.handleMouseInput(); if (!Display.isActive()) // Don't allow multiple URL-Clicks if Display is not focused. return; int mouseX = this.i; int mouseY = this.j; if (this.g(mouseY)) { if (Mouse.isButtonDown(0) && this.q()) { int y = mouseY - this.d - this.t + (int) this.n - 4; int id = -1; int minY = -1; // Search for the right ChatLine-ID for (int i1 = 0; i1 < heightMap.size(); i1++) { Integer integer = heightMap.get(i1); Row line = rows.get(i1); if (y >= integer - 2 && y <= integer + line.getLineHeight() - 2) { id = i1; minY = integer; break; } } if (id < 0 || id >= rows.size()) return; callback.chatLineClicked(rows.get(id), mouseX, y, minY, getLeft()); } } }