Jump to content

[1.7.10] Freeing cursor on keypress


Roboguy99

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Keep this post up just in case but I'm using the curseforge launcher and it's working  IM SOO HAPPY
    • Post logs as per https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/ They may have information that will answer these questions.
    • I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon I was left reeling when a glitch on a cryptocurrency exchange caused me to lose $166,000 worth of my hard-earned savings. It felt like my entire world had crumbled in the blink of an eye, leaving me with a sense of hopelessness. Determined not to give up, I delved into research on recovery options, unsure of what to expect. That's when I stumbled upon DIGITAL HACK RECOVERY, a beacon of hope in my darkest hour. Despite my initial doubts, I decided to take a leap of faith and give them a shot as a final lifeline. The experts at DIGITAL HACK RECOVERY proved to be masters of their craft, guiding me through their exclusive process with precision and expertise. Utilizing cutting-edge blockchain analysis methods, they were able to track down the elusive trail of my missing funds and identify the exact point of failure. Their forensic talents were unparalleled as they tirelessly combed through the intricate web of blockchain data to locate my cryptocurrency. With each step they took, they kept me informed of their progress, never wavering in their belief that my funds could be rescued. After several painstaking weeks, DIGITAL HACK RECOVERY finally located and restored my $166,000 worth of cryptocurrency. I was awestruck that they were able to salvage what I had thought was lost forever. The whole experience restored my faith in the crypto space and proved that even in the worst situations, recovery is possible with the right experts on your side. I will be forever grateful to DIGITAL HACK RECOVERY for giving me back my life savings when I needed it most. Their tireless efforts and technical mastery turned what could have been a devastating loss into an uplifting success story. Book a time with DIGITAL HACK RECOVERY through: digital hack recovery @ techie . com &  +12018871705
    • public class ParticleReboundRecipe implements Recipe<CraftingContainer> { private List<ParticleReboundIngredient> inputs; private ParticleReboundFuel fuel; private ItemStack output; public ParticleReboundRecipe(List<ParticleReboundIngredient> inputs, ParticleReboundFuel fuel, ItemStack output) { this.inputs = inputs; this.fuel = fuel; this.output = output; } // TODO: Implement interface ... // TODO: Move to separate file if desired public record ParticleReboundIngredient(Ingredient ingredient, int count) { public static final Codec<ParticleReboundIngredient> CODEC = RecordCodecBuilder.create( builder -> builder.group( Ingredient.CODEC.fieldOf("ingredient").forGetter((i) -> i.ingredient), Codec.INT.fieldOf("count").forGetter(i -> i.count) ).apply(builder, ParticleReboundIngredient::new) ); } // TODO: Move to separate file if desired public record ParticleReboundFuel(String tag) { public static final Codec<ParticleReboundFuel> CODEC = RecordCodecBuilder.create( builder -> builder.group(Codec.STRING.fieldOf("tag").forGetter(f -> f.tag)).apply(builder, ParticleReboundFuel::new) ); public boolean isFuel(ItemStack stack) { // TODO: Check if fuel item matches the tag } } public class Serializer implements RecipeSerializer<ParticleReboundRecipe> { public static final Codec<ParticleReboundRecipe> CODEC = RecordCodecBuilder.create( builder -> builder.group( ParticleReboundIngredient.CODEC.listOf().fieldOf("inputs").forGetter(r -> r.inputs), ParticleReboundFuel.CODEC.fieldOf("fuel").forGetter(r -> r.fuel), ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output) ).apply(builder, ParticleReboundRecipe::new) ); @Override public @NotNull Codec<ParticleReboundRecipe> codec() { return CODEC; } // TODO: The rest ... } }   ?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.