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

The following examples show how to use org.lwjgl.input.Mouse#isButtonDown() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: SkyblockAddons   File: EntityRendererHook.java    License: MIT License 6 votes vote down vote up
public static void removeEntities(List<Entity> list) {
    SkyblockAddons main = SkyblockAddons.getInstance();
    if (main.getUtils().isOnSkyblock()) {

        int keyCode = Minecraft.getMinecraft().gameSettings.keyBindUseItem.getKeyCode();
        boolean isUseKeyDown = false;
        try {
            if (keyCode < 0) {
                isUseKeyDown = Mouse.isButtonDown(Minecraft.getMinecraft().gameSettings.keyBindUseItem.getKeyCode() + 100);
            } else {
                isUseKeyDown = Keyboard.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindUseItem.getKeyCode());
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
            // Uhh I messed up something with the key detection... fix?
        }

        if (!GuiScreen.isCtrlKeyDown() && isUseKeyDown && main.getConfigValues().isEnabled(Feature.IGNORE_ITEM_FRAME_CLICKS)) {
            list.removeIf(listEntity -> listEntity instanceof EntityItemFrame &&
                    (((EntityItemFrame)listEntity).getDisplayedItem() != null || Minecraft.getMinecraft().thePlayer.getHeldItem() == null));
        }
        if (main.getConfigValues().isEnabled(Feature.HIDE_PLAYERS_NEAR_NPCS)) {
            list.removeIf(entity -> entity instanceof EntityOtherPlayerMP && NPCUtils.isNearAnyNPCWithTag(entity, Tag.IMPORTANT) && !NPCUtils.isNPC(entity));
        }
    }
}
 
Example 2
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    super.drawDefaultBackground();
    delete.enabled = (selected != null);
    changeType.enabled = (selected != null);
    changeKey.enabled = (selected != null);

    if (selected != null) {
        GuiBlock hitbox = selected.getKey().getHitbox().multiply(mod.getSettings().getScale());
        drawRect(hitbox.getLeft(), hitbox.getTop(), hitbox.getRight(), hitbox.getBottom(), Color.WHITE.getRGB());
        mod.getSettings().setKeyBackgroundOpacity(120);
    }

    mod.getRenderer().renderKeystrokes();
    super.drawScreen(mouseX, mouseY, partialTicks);

    if (selected != null && Mouse.isButtonDown(0) && currentlyDragging == null &&
        selected.getKey().getHitbox().multiply(mod.getSettings().getScale()).isMouseOver(mouseX, mouseY)) {
        currentlyDragging = selected;
    }
}
 
Example 3
@Override
public void render(int mouseX, int mouseY, float partialTick){
    GL11.glColor4d(1, 1, 1, 1);
    if(!Mouse.isButtonDown(0)) dragging = false;
    if(!wasClicking && Mouse.isButtonDown(0) && getBounds().contains(mouseX, mouseY)) {
        dragging = true;
    }
    if(!enabled) dragging = false;
    wasClicking = Mouse.isButtonDown(0);
    if(dragging) currentScroll = (float)(mouseY - 7 - getBounds().y) / (getBounds().height - 17);
    currentScroll = MathHelper.clamp_float(currentScroll, 0, 1);
    Minecraft.getMinecraft().getTextureManager().bindTexture(scrollTexture);
    Gui.func_146110_a(x, y, 12, 0, getBounds().width, 1, 26, 15);
    for(int i = 0; i < getBounds().height - 2; i++)
        Gui.func_146110_a(x, y + 1 + i, 12, 1, getBounds().width, 1, 26, 15);
    Gui.func_146110_a(x, y + getBounds().height - 1, 12, 14, getBounds().width, 1, 26, 15);

    if(!enabled) GL11.glColor4d(0.6, 0.6, 0.6, 1);
    Gui.func_146110_a(x + 1, y + 1 + (int)((getBounds().height - 17) * currentScroll), 0, 0, 12, 15, 26, 15);
    GL11.glColor4d(1, 1, 1, 1);
}
 
Example 4
@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 5
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
    if (tooltipBlockStack != null && !tooltipBlockStack.isEmpty() && !Mouse.isButtonDown(0)) {
        Minecraft minecraft = Minecraft.getMinecraft();
        ITooltipFlag flag = minecraft.gameSettings.advancedItemTooltips ? TooltipFlags.ADVANCED : TooltipFlags.NORMAL;
        List<String> tooltip = tooltipBlockStack.getTooltip(minecraft.player, flag);
        EnumRarity rarity = tooltipBlockStack.getRarity();
        for (int k = 0; k < tooltip.size(); ++k) {
            if (k == 0) {
                tooltip.set(k, rarity.rarityColor + tooltip.get(k));
            } else {
                tooltip.set(k, TextFormatting.GRAY + tooltip.get(k));
            }
        }
        return tooltip;
    }
    return Collections.emptyList();
}
 
Example 6
Source Project: ehacks-pro   File: FastEat.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onTicks() {
    if (this.isActive() && Mouse.getEventButton() == 1 && Mouse.isButtonDown(1)) {
        if (this.mode == 1) {
            int[] ignoredBlockIds = new int[]{23, 25, 26, 54, 58, 61, 62, 64, 69, 71, 77, 84, 92, 96, 107, 116, 117, 118, 120, 130, 137, 143, 145, 146, 149, 150, 154, 158};
            for (int id : ignoredBlockIds) {
                if (Block.getIdFromBlock(Wrapper.INSTANCE.world().getBlock(Wrapper.INSTANCE.mc().objectMouseOver.blockX, Wrapper.INSTANCE.mc().objectMouseOver.blockY, Wrapper.INSTANCE.mc().objectMouseOver.blockZ)) != id) {
                    continue;
                }
                return;
            }
        }
        if (Wrapper.INSTANCE.player().inventory.getCurrentItem() == null) {
            return;
        }
        Item item = Wrapper.INSTANCE.player().inventory.getCurrentItem().getItem();
        if (Wrapper.INSTANCE.player().onGround && (item instanceof ItemFood || item instanceof ItemPotion) && (Wrapper.INSTANCE.player().getFoodStats().needFood() || item instanceof ItemPotion || item instanceof ItemAppleGold)) {
            Wrapper.INSTANCE.player().sendQueue.addToSendQueue(new C09PacketHeldItemChange(Wrapper.INSTANCE.player().inventory.currentItem));
            for (int i = 0; i < 1000; ++i) {
                Wrapper.INSTANCE.player().sendQueue.addToSendQueue(new C03PacketPlayer(false));
            }
            Wrapper.INSTANCE.player().sendQueue.addToSendQueue(new C07PacketPlayerDigging(5, 0, 0, 0, 255));
        }
    }
}
 
Example 7
@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 8
private void apply(int mouseX, int mouseY) {
    if (mouseLock) return;
    if (!Mouse.isButtonDown(0)) return;
    if (!element.isColorPallet()) return;

    float scale = scale();
    int left = posX(1);
    int right = posX(2);
    int top = posY(1);
    int bottom = posY(3);
    float x;
    float y;

    if (mouseX > left && mouseX < right) {
        if (mouseY > top && mouseY < bottom) {
            x = mouseX - left;
            y = mouseY - top;
            x /= scale;
            y /= scale;

            if (y > 0 && y <= 256) {
                if (x < 256 && x > 0) {
                    hue = (int) x;
                    saturation = (int) (256 - y);
                    regenImage();
                    lastX = mouseX;
                    lastY = mouseY;
                } else if (x > 256 + 15 && x < 256 + 15 + 15) {
                    brightness = (int) y;
                    regenImage();
                }
            }
        }
    }
}
 
Example 9
Source Project: The-5zig-Mod   File: GuiListChat.java    License: MIT License 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example 10
Source Project: OpenGL-Animation   File: Camera.java    License: The Unlicense 5 votes vote down vote up
/**
 * Calculate the angle of the camera around the player (when looking down at
 * the camera from above). Basically the yaw. Changes the yaw when the user
 * moves the mouse horizontally with the LMB down.
 */
private void calculateAngleAroundPlayer() {
	if (Mouse.isButtonDown(0)) {
		float angleChange = Mouse.getDX() * YAW_SENSITIVITY;
		angleAroundPlayer.increaseTarget(-angleChange);
	}
	angleAroundPlayer.update(DisplayManager.getFrameTime());
}
 
Example 11
Source Project: The-5zig-Mod   File: GuiListChat.java    License: MIT License 5 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example 12
@Override
public void onMouse(MouseEvent event) {
    MovingObjectPosition mop = Wrapper.INSTANCE.mc().objectMouseOver;
    if (mop.sideHit == -1) {
        return;
    }
    boolean nowState = Mouse.isButtonDown(1);
    if (!prevState && nowState) {
        prevState = nowState;
        TileEntity entity = Wrapper.INSTANCE.world().getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
        try {
            if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && entity != null && !Class.forName("eu.thesociety.DragonbornSR.DragonsRadioMod.Block.TileEntity.TileEntityRadio").isInstance(entity)) {
                ByteBuf buf = Unpooled.buffer(0);
                buf.writeByte(0);
                buf.writeInt(0);
                buf.writeDouble(mop.blockX);
                buf.writeDouble(mop.blockY);
                buf.writeDouble(mop.blockZ);
                buf.writeInt(Wrapper.INSTANCE.player().dimension);
                buf.writeInt(0);
                buf.writeBytes(new byte[0]);
                buf.writeBoolean(false);
                buf.writeFloat(0);
                buf.writeDouble(0);
                buf.writeDouble(0);
                buf.writeDouble(0);
                C17PacketCustomPayload packet = new C17PacketCustomPayload("DragonsRadioMod", buf);
                Wrapper.INSTANCE.player().sendQueue.addToSendQueue(packet);
                InteropUtils.log("Crash sent", this);
                if (event.isCancelable()) {
                    event.setCanceled(true);
                }
            }
        } catch (Exception ex) {
            InteropUtils.log("Error happened", this);
        }
    }
    prevState = nowState;
}
 
Example 13
Source Project: LowPolyWater   File: Camera.java    License: The Unlicense 5 votes vote down vote up
/**
 * 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 14
Source Project: 3DGameEngine   File: Input.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean GetMouse(int mouseButton)
{
	return Mouse.isButtonDown(mouseButton);
}
 
Example 15
private boolean isKeyOrMouseDown(int keyCode) {
    return keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode);
}
 
Example 16
/**
 * Draws the screen and all the components in it.
 */
@Override
public void drawScreen(int par1, int par2, float par3){
    boolean flag = Mouse.isButtonDown(0);
    int k = guiLeft;
    int l = guiTop;
    int i1 = k + 156;
    int j1 = l + 48;
    int k1 = i1 + 14;
    int l1 = j1 + 112;
    if(!wasClicking && flag && par1 >= i1 && par2 >= j1 && par1 < k1 && par2 < l1) {
        isScrolling = needsScrollBars();
    }

    if(!flag) {
        isScrolling = false;
    }

    wasClicking = flag;

    if(isScrolling) {
        currentScroll = (par2 - j1 - 7.5F) / (l1 - j1 - 15.0F);

        if(currentScroll < 0.0F) {
            currentScroll = 0.0F;
        }

        if(currentScroll > 1.0F) {
            currentScroll = 1.0F;
        }

        ((ContainerSearcher)inventorySlots).scrollTo(currentScroll);
    }
    if(firstRun) {
        firstRun = false;
        ((ContainerSearcher)inventorySlots).scrollTo(0);
    }

    super.drawScreen(par1, par2, par3);

    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glDisable(GL11.GL_LIGHTING);
}
 
Example 17
Source Project: AdvancedRocketry   File: RocketEventHandler.java    License: MIT License 4 votes vote down vote up
@SubscribeEvent
public void mouseInputEvent(MouseInputEvent event) {
	if(!Configuration.lockUI && !Mouse.isGrabbed()) {

		if(Mouse.isButtonDown(2)) {
			ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
			int i = scaledresolution.getScaledWidth();
			int j = scaledresolution.getScaledHeight();
			int mouseX =  Mouse.getX() * i / Minecraft.getMinecraft().displayWidth;
			int mouseY = j - Mouse.getY() * j / Minecraft.getMinecraft().displayHeight - 1;

			if(currentlySelectedBox == null && mouseX >= suitPanel.getX(i) && mouseX < suitPanel.getX(i) + suitPanel.sizeX &&
					mouseY >= suitPanel.getY(j) && mouseY < suitPanel.getY(j) + suitPanel.sizeY) {
				currentlySelectedBox = suitPanel;
			}

			if(currentlySelectedBox == null && mouseX >= oxygenBar.getX(i) && mouseX < oxygenBar.getX(i) + oxygenBar.sizeX &&
					mouseY >= oxygenBar.getY(j) && mouseY < oxygenBar.getY(j) + oxygenBar.sizeY) {
				currentlySelectedBox = oxygenBar;
			}

			if(currentlySelectedBox == null && mouseX >= hydrogenBar.getX(i) && mouseX < hydrogenBar.getX(i) + hydrogenBar.sizeX &&
					mouseY >= hydrogenBar.getY(j) && mouseY < hydrogenBar.getY(j) + hydrogenBar.sizeY) {
				currentlySelectedBox = hydrogenBar;
			}
			
			if(currentlySelectedBox == null && mouseX >= atmBar.getX(i) && mouseX < atmBar.getX(i) + atmBar.sizeX &&
					mouseY >= atmBar.getY(j) && mouseY < atmBar.getY(j) + atmBar.sizeY) {
				currentlySelectedBox = atmBar;
			}
			
			if(currentlySelectedBox != null) {

				currentlySelectedBox.setRenderX(mouseX, i);
				currentlySelectedBox.setRenderY(mouseY, j);
			}
		}
		else
			currentlySelectedBox = null;
	}
}
 
Example 18
public void updatePressed() {
    wasPressed = Mouse.isButtonDown(0);
}
 
Example 19
@Listener
public void onRenderTooltip(EventRenderTooltip event) {
    if (event.getItemStack() == null)
        return;

    final Minecraft mc = Minecraft.getMinecraft();

    if (event.getItemStack().getItem() instanceof ItemShulkerBox) {
        ItemStack shulker = event.getItemStack();
        NBTTagCompound tagCompound = shulker.getTagCompound();
        if (tagCompound != null && tagCompound.hasKey("BlockEntityTag", 10)) {
            NBTTagCompound blockEntityTag = tagCompound.getCompoundTag("BlockEntityTag");
            if (blockEntityTag.hasKey("Items", 9)) {
                event.setCanceled(true); // cancel rendering the old tooltip

                NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
                ItemStackHelper.loadAllItems(blockEntityTag, nonnulllist); // load the itemstacks from the tag to the list

                // store mouse/event coords
                int x = event.getX();
                int y = event.getY();

                // translate to mouse x, y
                GlStateManager.translate(x + 10, y - 5, 0);

                GlStateManager.disableLighting();
                GlStateManager.disableDepth();
                // background
                RenderUtil.drawRect(-3, -mc.fontRenderer.FONT_HEIGHT - 4, 9 * 16 + 3, 3 * 16 + 3, 0x99101010);
                RenderUtil.drawRect(-2, -mc.fontRenderer.FONT_HEIGHT - 3, 9 * 16 + 2, 3 * 16 + 2, 0xFF202020);
                RenderUtil.drawRect(0, 0, 9 * 16, 3 * 16, 0xFF101010);

                // text
                mc.fontRenderer.drawStringWithShadow(shulker.getDisplayName(), 0, -mc.fontRenderer.FONT_HEIGHT - 1, 0xFFFFFFFF);

                GlStateManager.enableDepth();
                mc.getRenderItem().zLevel = 150.0F;
                RenderHelper.enableGUIStandardItemLighting();

                // loop through items in shulker inventory
                for (int i = 0; i < nonnulllist.size(); i++) {
                    ItemStack itemStack = nonnulllist.get(i);
                    int offsetX = (i % 9) * 16;
                    int offsetY = (i / 9) * 16;
                    mc.getRenderItem().renderItemAndEffectIntoGUI(itemStack, offsetX, offsetY);
                    mc.getRenderItem().renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, offsetX, offsetY, null);
                }

                RenderHelper.disableStandardItemLighting();
                mc.getRenderItem().zLevel = 0.0F;
                GlStateManager.enableLighting();

                // reverse the translate
                GlStateManager.translate(-(x + 10), -(y - 5), 0);
            }
        }

        if(this.middleClick.getValue()) {
            if (Mouse.isButtonDown(2)) {
                if (!this.clicked) {
                    final BlockShulkerBox shulkerBox = (BlockShulkerBox) Block.getBlockFromItem(shulker.getItem());
                    if (shulkerBox != null) {
                        final NBTTagCompound tag = shulker.getTagCompound();
                        if (tag != null && tag.hasKey("BlockEntityTag", 10)) {
                            final NBTTagCompound entityTag = tag.getCompoundTag("BlockEntityTag");

                            final TileEntityShulkerBox te = new TileEntityShulkerBox();
                            te.setWorld(mc.world);
                            te.readFromNBT(entityTag);
                            mc.displayGuiScreen(new GuiShulkerBox(mc.player.inventory, te));
                        }
                    }
                }
                this.clicked = true;
            } else {
                this.clicked = false;
            }
        }
    }
}
 
Example 20
public MoveElementGui(ChromaHUD mod, DisplayElement element) {
    this.mod = mod;
    this.element = element;
    mouseLock = Mouse.isButtonDown(0);
}