net.minecraft.util.MovingObjectPosition#org.lwjgl.input.Mouse源码实例Demo

下面列出了net.minecraft.util.MovingObjectPosition#org.lwjgl.input.Mouse 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FEMultiPlayer-V2   文件: Game.java
/**
 * 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);
	}
}
 
源代码2 项目: jmonkeyengine   文件: LwjglCanvas.java
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();
}
 
源代码3 项目: ForgeHax   文件: GuiWindowMod.java
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;
  }
}
 
源代码4 项目: ehacks-pro   文件: ExtendedDestroyer.java
@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) {

    }
}
 
源代码5 项目: ehacks-pro   文件: CarpenterOpener.java
@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) {

    }
}
 
源代码6 项目: enderutilities   文件: GuiEnderUtilities.java
@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();
    }
}
 
源代码7 项目: Cyberware   文件: GuiEngineeringTable.java
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);
	}
}
 
源代码8 项目: ehacks-pro   文件: SpaceFire.java
@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) {

    }
}
 
源代码9 项目: malmo   文件: MalmoModClient.java
@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());
    }
}
 
源代码10 项目: Slyther   文件: DefaultController.java
@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;
        }
    }
}
 
源代码11 项目: Hyperium   文件: CPSKey.java
@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);
    }
}
 
源代码12 项目: MinecraftX-RAY   文件: XrayModChooserGui.java
@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));
		}
	}
}
 
源代码13 项目: LiquidBounce   文件: SlowlyStyle.java
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;
}
 
源代码14 项目: GregTech   文件: AdvancedTextWidget.java
@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;
}
 
源代码15 项目: ehacks-pro   文件: ShowContainer.java
@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) {

    }
}
 
源代码16 项目: Hyperium   文件: Utils.java
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) {
    }
}
 
源代码17 项目: ehacks-pro   文件: FakeDestroy.java
@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) {

    }
}
 
源代码18 项目: Hyperium   文件: GuiScreenEditKeys.java
@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();
}
 
源代码19 项目: slick2d-maven   文件: AppletGameContainer.java
/**
    * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.opengl.ImageData, int, int)
    */
   public void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException {
      try {
         Cursor cursor = CursorLoader.get().getCursor(data, hotSpotX, hotSpotY);
         Mouse.setNativeCursor(cursor);
      } catch (Throwable e) {
         Log.error("Failed to load and apply cursor.", e);
throw new SlickException("Failed to set mouse cursor", e);
      }
   }
 
源代码20 项目: SkyblockAddons   文件: ButtonLocation.java
/**
 * This just updates the hovered status and draws the box around each feature. To avoid repetitive code.
 */
public void checkHoveredAndDrawBox(float boxXOne, float boxXTwo, float boxYOne, float boxYTwo, float scale) {
    ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
    float minecraftScale = sr.getScaleFactor();
    float floatMouseX = Mouse.getX() / minecraftScale;
    float floatMouseY = (Minecraft.getMinecraft().displayHeight - Mouse.getY()) / minecraftScale;

    hovered = floatMouseX >= boxXOne * scale && floatMouseY >= boxYOne * scale && floatMouseX < boxXTwo * scale && floatMouseY < boxYTwo * scale;
    int boxAlpha = 70;
    if (hovered) {
        boxAlpha = 120;
    }
    int boxColor = ChatFormatting.GRAY.getColor(boxAlpha).getRGB();
    main.getUtils().drawRect(boxXOne, boxYOne, boxXTwo, boxYTwo, boxColor);

    this.boxXOne = boxXOne;
    this.boxXTwo = boxXTwo;
    this.boxYOne = boxYOne;
    this.boxYTwo = boxYTwo;

    if (this.feature == Feature.DEFENCE_ICON) {
        this.boxXOne *= scale;
        this.boxXTwo *= scale;
        this.boxYOne *= scale;
        this.boxYTwo *= scale;
    }

    this.scale = scale;
}
 
源代码21 项目: SkyblockAddons   文件: ButtonResize.java
@Override
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
    ScaledResolution sr = new ScaledResolution(mc);
    float minecraftScale = sr.getScaleFactor();
    float floatMouseX = Mouse.getX() / minecraftScale;
    float floatMouseY = (mc.displayHeight - Mouse.getY()) / minecraftScale;

    cornerOffsetX = floatMouseX;
    cornerOffsetY = floatMouseY;

    return hovered;
}
 
源代码22 项目: OpenModsLib   文件: Trackball.java
public void update(int mouseX, int mouseY) {
	float mx = mouseX / radius;
	float my = mouseY / radius;

	boolean buttonState = Mouse.isButtonDown(mouseButton);
	if (!isDragging && buttonState) {
		isDragging = true;
		target.startDrag(mx, my);
	} else if (isDragging && !buttonState) {
		isDragging = false;
		target.endDrag(mx, my);
	}

	target.applyTransform(mx, my, isDragging);
}
 
源代码23 项目: Hyperium   文件: ElementRenderer.java
private void renderElements() {
    if (fontRendererObj == null) fontRendererObj = Minecraft.getMinecraft().fontRendererObj;

    // Mouse Button Left
    boolean m = Mouse.isButtonDown(0);
    if (m != last) {
        last = m;
        if (m) clicks.add(System.currentTimeMillis());
    }

    // Mouse Button Right
    boolean rm = Mouse.isButtonDown(1);
    if (rm != rLast) {
        rLast = rm;
        if (rm) rClicks.add(System.currentTimeMillis());
    }

    // Others
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

    List<DisplayElement> elementList = mod.getDisplayElements();
    elementList.forEach(element -> {
        startDrawing(element);
        try {
            element.draw();
        } catch (Exception ignored) {
        }
        endDrawing(element);
    });
}
 
源代码24 项目: WearableBackpacks   文件: GuiContainerScreen.java
@Override
public void handleMouseInput() throws IOException {
	super.handleMouseInput();
	
	int mouseX = Mouse.getEventX() * width / mc.displayWidth;
	int mouseY = height - Mouse.getEventY() * height / mc.displayHeight - 1;
	
	int scroll = Integer.signum(Mouse.getEventDWheel());
	if (scroll != 0) container.onMouseScroll(scroll, mouseX, mouseY);
}
 
源代码25 项目: The-5zig-Mod   文件: Gui2ndChat.java
@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);
	}
}
 
源代码26 项目: PneumaticCraft   文件: GuiSearcher.java
/**
 * Handles mouse input.
 */
@Override
public void handleMouseInput(){
    super.handleMouseInput();
    int i = Mouse.getEventDWheel();

    if(i != 0 && needsScrollBars()) {
        int j = ((ContainerSearcher)inventorySlots).itemList.size() / 9 - 5 + 1;

        if(i > 0) {
            i = 1;
        }

        if(i < 0) {
            i = -1;
        }

        currentScroll = (float)(currentScroll - (double)i / (double)j);

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

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

        ((ContainerSearcher)inventorySlots).scrollTo(currentScroll);
    }
}
 
源代码27 项目: The-5zig-Mod   文件: GuiListChat.java
/**
 * 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());
		}
	}
}
 
源代码28 项目: MikuMikuStudio   文件: LwjglMouseInput.java
public void setCursorVisible(boolean visible){
    cursorVisible = visible;
    if (!context.isRenderable())
        return;
    
    Mouse.setGrabbed(!visible);
}
 
源代码29 项目: The-5zig-Mod   文件: Gui2ndChat.java
@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())) : ((bgr) MinecraftFactory.getVars().getMinecraftScreen()).a(getChatComponent(Mouse.getX(), Mouse.getY())));
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
源代码30 项目: ToroQuest   文件: VillageLordGuiContainer.java
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);
		}
	}
}