Java Code Examples for org.lwjgl.input.Mouse#getEventButtonState()

The following examples show how to use org.lwjgl.input.Mouse#getEventButtonState() . 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: ManualDeleteMod.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onInput(MouseEvent event) {
  if (getWorld() == null || getLocalPlayer() == null) {
    return;
  }
  
  if (event.getButton() == 2 && Mouse.getEventButtonState()) { // on middle click
    RayTraceResult aim = MC.objectMouseOver;
    if (aim == null) {
      return;
    }
    if (aim.typeOfHit == RayTraceResult.Type.ENTITY) {
      if (aim.entityHit != null) {
        MC.world.removeEntity(aim.entityHit);
      }
    }
  }
}
 
Example 2
Source File: Game.java    From FEMultiPlayer-V2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 3
Source File: ContainerEventHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SubscribeEvent (priority = EventPriority.LOWEST, receiveCanceled = true)//We need to be called before JEI.
public void onGuiMouseEventpre(MouseInputEvent.Pre event) {
    if (Mouse.getEventButton() == -1 || event.getGui() == null || !Mouse.getEventButtonState()) {
        return;
    }
    Point mouse = GuiDraw.getMousePosition();
    int eventButton = Mouse.getEventButton();
    if (JEIIntegrationManager.searchBoxOwner == EnumItemBrowser.JEI) {
        GuiTextFieldFilter fieldFilter = JEIIntegrationManager.getTextFieldFilter();
        if (fieldFilter != null && fieldFilter.isMouseOver(mouse.x, mouse.y)) {
            if (eventButton == 0) {
                if (fieldFilter.isFocused() && (System.currentTimeMillis() - lastSearchBoxClickTime < 500)) {//double click
                    NEIClientConfig.world.nbt.setBoolean("searchinventories", !SearchField.searchInventories());
                    NEIClientConfig.world.saveNBT();
                    lastSearchBoxClickTime = 0L;
                } else {
                    lastSearchBoxClickTime = System.currentTimeMillis();
                }
            } else if (eventButton == 1) {
                NEIClientConfig.setSearchExpression("", false);
                LayoutManager.searchField.setText("", false);
            }
        }
    }
}
 
Example 4
Source File: Game.java    From FEMultiplayer with GNU General Public License v3.0 6 votes vote down vote up
public static void getInput() {
	Keyboard.poll();
	keys.clear();
	while(Keyboard.next()) {
		KeyboardEvent ke = new KeyboardEvent(
				Keyboard.getEventKey(),
				Keyboard.getEventCharacter(),
				Keyboard.isRepeatEvent(),
				Keyboard.getEventKeyState());
		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: XrayModChooserGui.java    From MinecraftX-RAY with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 6
Source File: SignTextMod.java    From ForgeHax with MIT License 5 votes vote down vote up
@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 7
Source File: VillageLordGuiContainer.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private void drawDonateButton(int mouseX, int mouseY) {
	GuiButton submitButton = new GuiButton(0, guiLeft + 105, guiTop + 15, buttonWidth, buttonHeight, I18n.format("quest.gui.button.donate"));
	submitButton.drawButton(mc, mouseX, mouseY, 1);
	if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1) {
		if (submitButton.mousePressed(mc, mouseX, mouseY) && mouseCooldownOver()) {
			mousePressed = Minecraft.getSystemTime();
			MessageQuestUpdate message = new MessageQuestUpdate();
			message.action = Action.DONATE;
			message.lordEntityId = inventory.getEntityId();
			ToroQuestPacketHandler.INSTANCE.sendToServer(message);
		}
	}
}
 
Example 8
Source File: VillageLordGuiContainer.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void drawActionButton(String label, Action action, int mouseX, int mouseY, int xOffset) {
	GuiButton abandonButton = new GuiButton(0, guiLeft + 105 + xOffset, guiTop + 130, buttonWidth, buttonHeight, I18n.format(label));
	abandonButton.drawButton(mc, mouseX, mouseY, 1);
	if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1) {
		if (abandonButton.mousePressed(mc, mouseX, mouseY) && mouseCooldownOver()) {
			mousePressed = Minecraft.getSystemTime();
			MessageQuestUpdate message = new MessageQuestUpdate();
			message.action = action;
			message.lordEntityId = inventory.getEntityId();
			ToroQuestPacketHandler.INSTANCE.sendToServer(message);
		}
	}
}
 
Example 9
Source File: Scrollbar.java    From Chisel with GNU General Public License v2.0 5 votes vote down vote up
public void handleMouseInput()
{
    if(Mouse.getEventButton() == 0 && !Mouse.getEventButtonState())
    {
        dragged = false;
    }

    if(!active)
    {
        return;
    }

    float initialOffset = offset;
    int direction = Mouse.getEventDWheel();

    if(direction != 0)
    {
        offset += direction > 0 ? -step : step;
    }

    if(offset < 0)
    {
        offset = 0;
    }

    if(offset > 1)
    {
        offset = 1;
    }

    if(initialOffset != offset)
    {
        onScrolled(offset);
    }
}
 
Example 10
Source File: GuiCapture.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Override
public void handleMouseInput() {
	super.handleMouseInput();

	final int button = Mouse.getEventButton();
	final int wheel = Mouse.getEventDWheel();
	final int mx = Mouse.getEventX();
	final int my = Mouse.getEventY();

	final float scaleX = (float)this.width / this.mc.displayWidth;
	final float scaleY = (float)this.height / this.mc.displayHeight;

	final float x = mx * scaleX;
	final float y = this.height - my * scaleY;

	if (button != -1 || wheel != 0) {
		final ScaledResolution resolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
		final DrawableHitInfo hit = TerminalManagerClient.instance.findDrawableHit(guid, resolution, x, y);

		if (button != -1) {
			final boolean state = Mouse.getEventButtonState();
			createMouseButtonEvent(button, state, hit).sendToServer();
			final boolean draggingStarted = updateButtonCounter(state);
			if (draggingStarted) resetDraggingLimiter(x, y);
		}

		if (wheel != 0) createMouseWheelEvent(wheel, hit).sendToServer();
	}

	{
		final float dx = (x - lastDragX);
		final float dy = (y - lastDragY);

		if (canSendDragEvent(dx, dy)) {
			createDragEvent(dx, dy).sendToServer();
			resetDraggingLimiter(x, y);
		}
	}

}
 
Example 11
Source File: HyperiumMinecraft.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void runTickMouseButton() {
    // Activates for EVERY mouse button.
    int i = Mouse.getEventButton();
    boolean state = Mouse.getEventButtonState();
    EventBus.INSTANCE.post(state ? new MouseButtonEvent(i, true) : new MouseButtonEvent(i, false));
}
 
Example 12
Source File: GuiScreenPlus.java    From Chisel with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleMouseInput()
{
    mouseEvent.handled = false;
    mouseEvent.x = Mouse.getEventX() * width / mc.displayWidth - this.screenX;
    mouseEvent.y = height - Mouse.getEventY() * height / mc.displayHeight - 1 - this.screenY;

    if(oldX == -1)
    {
        oldX = mouseEvent.x;
        oldY = mouseEvent.y;
    }

    mouseEvent.dx = mouseEvent.x - oldX;
    mouseEvent.dy = mouseEvent.y - oldY;
    oldX = mouseEvent.x;
    oldY = mouseEvent.y;
    mouseEvent.down = Mouse.getEventButtonState();
    mouseEvent.button = Mouse.getEventButton();
    mouseEvent.wheel = Mouse.getEventDWheel();

    if(mouseEvent.wheel != 0)
    {
        if(mouseEvent.wheel < 0)
        {
            mouseEvent.wheel = -1;
        } else
        {
            mouseEvent.wheel = 1;
        }

        root.mouseWheel(mouseEvent);
    } else if(mouseEvent.button >= 0 && mouseEvent.button < downButtons.length)
    {
        if(downButtons[mouseEvent.button] != mouseEvent.down)
        {
            downButtons[mouseEvent.button] = mouseEvent.down;

            if(mouseEvent.down)
            {
                root.mouseDown(mouseEvent);
            } else
            {
                root.mouseUp(mouseEvent);
            }
        } else if(mouseEvent.dx != 0 || mouseEvent.dy != 0)
        {
            root.mouseMove(mouseEvent);
        }
    } else if(mouseEvent.dx != 0 || mouseEvent.dy != 0)
    {
        root.mouseMove(mouseEvent);
    }

    if(!mouseEvent.handled)
    {
        super.handleMouseInput();
    }
}