Posted September 6, 201510 yr I want to make it so when the player presses a key (my keybind is already working) the cursor is unlocked from the centre like when you use a Gui, and locked again when the player lets go. How would I do this? I have no idea what I'm doing.
September 6, 201510 yr It REALLY depends on what should happen during free-cursor time. Present whole idea. 1.7.10 is no longer supported by forge, you are on your own.
September 6, 201510 yr Author It REALLY depends on what should happen during free-cursor time. Present whole idea. So the idea is when the player holds down a key, a HUD appears showing items stored in an inventory in a GTA V-style weapon wheel. The rendering is all done, but I'd like the user to be able to move their cursor over one of the options and click (or move the cursor and let go of the key without clicking, doesn't really matter). So I need to know the mouse co-ordinates and possibly when they click essentially. I have no idea what I'm doing.
September 6, 201510 yr Can't you just open/close Gui on down/up button press? And on unpress get position of mouse related to center which will tell you to what side you hovered (e.g hovered to the left to pick left slot)? 1.7.10 is no longer supported by forge, you are on your own.
September 6, 201510 yr Author Can't you just open/close Gui on down/up button press? And on unpress get position of mouse related to center which will tell you to what side you hovered (e.g hovered to the left to pick left slot)? My weapon wheel is rendered straight onto the HUD because it was easier to dynamically adjust the size this way. Would opening a GUI still work, and would I just have to open it client-side? I have no idea what I'm doing.
September 6, 201510 yr should work since ur gui isnt doing anything on server side. just send a packet for selecting the weapon
September 6, 201510 yr K: well for a start you'll want an event set to @SubscribeEvent public void onRenderTick(RenderTickEvent event){ if (event.phase == Phase.START&& your boolean or whatever ){ Minecraft.getMinecraft().mouseObject.objectMouseOver.typeOfHit = MovingObjectType.MISS; } } This will prevent the player from being able to select anything. I think theres a boolean or something that handles if the mouse is rendered/moved, but I'm not too sure Edit: Look for something around these (not accurate names) org.lwjgl.input.Mouse.create(); this.mouseHelper = new net.minecraft.src.MouseHelper(this.mcCanvas); "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
September 7, 201510 yr Lol forget all of that. Its really easy Minecraft.getMinecraft().setIngameNotInFocus(); Plz give me thx "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
September 7, 201510 yr Author Lol forget all of that. Its really easy Minecraft.getMinecraft().setIngameNotInFocus(); Plz give me thx This seems like it should work. I'm going to have to play with it a bit, because you have to manually re-set the focus when the key is no longer pressed. should work since ur gui isnt doing anything on server side. just send a packet for selecting the weapon If the other method doesn't work, I will use a GUI. It sounds easy enough, although I'll need to find out how packets work. I have no idea what I'm doing.
September 7, 201510 yr Author Ok so I can unfocus the game without a problem, but making sure it's focussed again when the button is released is quite hard: a) I don't wan't to keep the game focussed even when other HUD elements (i.e the chat or pause menu) are trying to open because this breaks them and b) I want my HUD element to appear for more than one frame. I suppose what I'm asking by hinting at my problems is how do I toggle the focus on button press without keeping it stuck in focus the whole time the button is not pressed? Would I need to write a keyUp method (this could do with being implemented into Forge, I might look into writing and pushing it when I've got time), or is there a better way? Here's the whole class (mostly) to (maybe) make life easier: public class EventsHandler extends Gui { private static final int RADIUS = 100; private static final int ITEM_RADIUS = 85; private static final int TOTAL_SECTORS = 20000; // Total number of small sectors, essentially circle definition private Random random = new Random(); private static final Minecraft minecraft = Minecraft.getMinecraft(); private RenderBlocks renderBlocksRi = new RenderBlocks(); private boolean renderWithColor = true; private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); private boolean keyPressed, keyPressedAndWasDrawing; @SideOnly(Side.CLIENT) @SubscribeEvent(priority = EventPriority.NORMAL) public void onRenderExperienceBar(RenderGameOverlayEvent.Post event) { Item holding; if (minecraft.thePlayer.getHeldItem() != null) { if (event.type == ElementType.ALL) { holding = minecraft.thePlayer.getHeldItem().getItem(); if(holding instanceof ItemBag && HotbarBag.bagHUD.getIsKeyPressed()) { keyPressed = true; BagInventory inventory = new BagInventory(minecraft.thePlayer.getHeldItem()); int items = 0; for(int i = 0; i < inventory.getSizeInventory(); i++) { if (inventory.getStackInSlot(i) != null) items++; } if (items != 0) { minecraft.setIngameNotInFocus(); List<ItemStack> inventoryContentsList = new ArrayList<ItemStack>(); for(int i = 0; i < inventory.getSizeInventory(); i++) { if (inventory.getStackInSlot(i) != null) { inventoryContentsList.add(inventory.getStackInSlot(i)); } } ItemStack[] inventoryContents = inventoryContentsList.toArray(new ItemStack[inventoryContentsList.size()]); float x = event.resolution.getScaledWidth() / 2; float y = event.resolution.getScaledHeight() / 2 - 15; double multiplier = this.TOTAL_SECTORS / items; // Brace for ugly maths! TODO make maths look less ugly GL11.glPushMatrix(); { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glColor4f(0.5F, 0.5F, 0.5F, 0.6F); GL11.glBegin(GL11.GL_TRIANGLE_FAN); { GL11.glVertex2f(x, y); for(int i = 0; i < items; i++) // Draw circle { // GL11.glColor4f(random.nextFloat(), // random.nextFloat(), random.nextFloat(), // 0.6F); //This is not very nice to look // at, but nice to debug for(double j = 0 + (i * multiplier); j <= (this.TOTAL_SECTORS / items) + (i * multiplier); j += 1) // Draw circle sector { double t = 2 * Math.PI * (float) j / (float) this.TOTAL_SECTORS; GL11.glVertex2d(x + Math.sin(t) * this.RADIUS, y + Math.cos(t) * this.RADIUS); } } } GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D); } GL11.glPopMatrix(); double radiansPerSector = (2 * Math.PI) / items; double offset = 0; if (inventoryContents.length % 2 == 0) offset = radiansPerSector / 2; for(int i = 0; i < inventoryContents.length; i++) { double radians = offset + (radiansPerSector * i) - (Math.PI / 2); double itemX = this.ITEM_RADIUS * Math.cos(radians) + x - 8; double itemY = this.ITEM_RADIUS * Math.sin(radians) + y - 8; this.renderItemIntoGUI(minecraft.fontRenderer, minecraft.getTextureManager(), inventoryContents[i], itemX, itemY, true); //Copied and changed to accept doubles instead of ints } } } if (keyPressed && !minecraft.inGameHasFocus) //My attempts so far, which means other HUD elements work but mine only renders for 1 frame. { keyPressedAndWasDrawing = true; minecraft.setIngameFocus(); keyPressed = false; } } keyPressed = false; keyPressedAndWasDrawing = false; } } I have no idea what I'm doing.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.