Jump to content

[SOLVED] Changing items texture when the mouse is over the item in the inventory


Kwibble

Recommended Posts

As the question states, I want to change the texture of my item (only the one under the mouse) to another one when the mouse is hovering over it.

 

Does anyone have any ideas and or suggestions on how to go about this? Thanks.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Thanks diesieben07 for the idea.

 

However, I am having an annoying time trying to implement it!

 

I have this:

GuiScreen currentScreen = ModuleDendri.proxy.getCurrentScreen();

if (currentScreen != null)
{
if (currentScreen instanceof GuiContainer)
{
        	Container container = ( (GuiContainer) currentScreen ).inventorySlots;

        	for (int j = 0; j < container.inventorySlots.size(); ++j)
	{
		Slot slot = (Slot) container.inventorySlots.get(j);

		if (slot.getStack() != null)
		{
			if (slot.getStack().getItem() == ItemDendri.mist_bottle)
			{
				int x = slot.xDisplayPosition - 1;
				int y = slot.yDisplayPosition - 1;
				int mouseX = Mouse.getX();
				int mouseY = this.flippedMouseY();

                        	if (mouseX >= ( x ) && mouseX <= ( x + 17 ))
				{
					if (mouseY >= ( y ) && mouseY <= ( y + 17 ))
					{
						return this.spriteIcons[getSpriteIndex(this.containedDendri)];
					}
				}
			}
		}
	}
}
}

 

And the slot coordinates are so wrong it's not funny. Here is an example of the coordinates:

Slot X: 62
Slot Y: 111
Mouse X: 374
Mouse Y: 348

 

So what I need now is a way to move my slot coordinates to the right spot, or to have the mouse coordinates translated to the right spot. And I don't want to just go about and say Mouse.getX() - 200; or something like that. Unless of course that works when you resize the screen... (Which I highly doubt).

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

What would you suggest is doing it?

 

This is what they use:

        this.mc.mcProfiler.startSection("mouse");

        if (this.mc.inGameHasFocus && flag)
        {
            this.mc.mouseHelper.mouseXYChange();
            float f1 = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
            float f2 = f1 * f1 * f1 * 8.0F;
            float f3 = (float)this.mc.mouseHelper.deltaX * f2;
            float f4 = (float)this.mc.mouseHelper.deltaY * f2;
            byte b0 = 1;

            if (this.mc.gameSettings.invertMouse)
            {
                b0 = -1;
            }

            if (this.mc.gameSettings.smoothCamera)
            {
                this.smoothCamYaw += f3;
                this.smoothCamPitch += f4;
                float f5 = par1 - this.smoothCamPartialTicks;
                this.smoothCamPartialTicks = par1;
                f3 = this.smoothCamFilterX * f5;
                f4 = this.smoothCamFilterY * f5;
                this.mc.thePlayer.setAngles(f3, f4 * (float)b0);
            }
            else
            {
                this.mc.thePlayer.setAngles(f3, f4 * (float)b0);
            }
        }

        this.mc.mcProfiler.endSection();

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Thanks so much diesieben07!

 

For anyone who is wanting to know how to do it, here is what I used:

        @Override
public IIcon getIconIndex(ItemStack par1ItemStack)
{
	if (this.containsDendri)
	{
		GuiScreen currentScreen = ModuleDendri.proxy.getCurrentScreen();

		if (currentScreen != null)
		{
			if (currentScreen instanceof GuiContainer)
			{
				Container container = ( (GuiContainer) currentScreen ).inventorySlots;

				for (int j = 0; j < container.inventorySlots.size(); ++j)
				{
					Slot slot = (Slot) container.inventorySlots.get(j);

					if (slot.getStack() != null)
					{
						if (slot.getStack() == par1ItemStack)
						{
							Minecraft mc = Minecraft.getMinecraft();
							ScaledResolution sr = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
							final int x = slot.xDisplayPosition - 1;
							final int y = slot.yDisplayPosition - 1;
							final int width = sr.getScaledWidth();
							final int height = sr.getScaledHeight();
							final int guiLeft = (width - 176) / 2;
							final int guiTop = (height - 166) / 2;
							final int mouseX = (Mouse.getX() * width / mc.displayWidth) - guiLeft + 9;
							final int mouseY = (height - Mouse.getY() * height / mc.displayHeight - 1) - guiTop - 15;

							if (mouseX >= ( x ) && mouseX <= ( x + 17 ))
							{
								if (mouseY >= ( y ) && mouseY <= ( y + 17 ))
								{
									return this.symbolIcons[getSymbolIndexForContainedDendri()];
								}
							}
						}
					}
				}
			}
		}
		return this.icons[1];
	}
	return this.icons[0];
}

We all stuff up sometimes... But I seem to be at the bottom of that pot.

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

    • It all began with a chance encounter with a testimonial shared by Olivia, a fellow traveler on the winding road of cryptocurrency. Her words spoke of a miraculous recovery orchestrated by Wizard Web Recovery, a beacon of hope in the murky waters of online fraud. Intrigued by her story, I reached out to Wizard Web Recovery, hoping they could work their magic on my blocked crypto recovery. With bated breath, I shared my plight, providing evidence of my dilemma and praying for a solution. To my astonishment, a prompt response came, swift and reassuring. Wizard Web Recovery wasted no time in assessing my situation, guiding me through the process with patience and expertise. and then like a ray of sunshine breaking through the clouds, came the news I had longed for – a new private key had been generated, restoring my precious bitcoins. It was a moment of jubilation, a triumph over adversity that filled me with newfound hope. At that moment, I realized the true power of Wizard Web Recovery, not just as skilled technicians, but as guardians of trust in the digital realm. With their assistance, I reclaimed what was rightfully mine, turning despair into determination and paving the way for a brighter future. But their capabilities did not end there. Delving deeper into their expertise, I discovered that Wizard Web Recovery possessed a wealth of knowledge in reclaiming lost stolen cryptocurrency, and even exposing fraudulent investment schemes. So to all those who find themselves entangled in the web of online fraud, take heart. With the guidance of Wizard Web Recovery, there is a path to redemption.     Write Mail; ( Wizard webrecovery AT  vprogrammer. net ) 
    • It all began with a chance encounter with a testimonial shared by Olivia, a fellow traveler on the winding road of cryptocurrency. Her words spoke of a miraculous recovery orchestrated by Wizard Web Recovery, a beacon of hope in the murky waters of online fraud. Intrigued by her story, I reached out to Wizard Web Recovery, hoping they could work their magic on my blocked crypto recovery. With bated breath, I shared my plight, providing evidence of my dilemma and praying for a solution. To my astonishment, a prompt response came, swift and reassuring. Wizard Web Recovery wasted no time in assessing my situation, guiding me through the process with patience and expertise. and then like a ray of sunshine breaking through the clouds, came the news I had longed for – a new private key had been generated, restoring my precious bitcoins. It was a moment of jubilation, a triumph over adversity that filled me with newfound hope. At that moment, I realized the true power of Wizard Web Recovery, not just as skilled technicians, but as guardians of trust in the digital realm. With their assistance, I reclaimed what was rightfully mine, turning despair into determination and paving the way for a brighter future. But their capabilities did not end there. Delving deeper into their expertise, I discovered that Wizard Web Recovery possessed a wealth of knowledge in reclaiming lost stolen cryptocurrency, and even exposing fraudulent investment schemes. So to all those who find themselves entangled in the web of online fraud, take heart. With the guidance of Wizard Web Recovery, there is a path to redemption.    
    • How can I add drops when killing an entity? Now there are no drops. How can I add an @override to change the attack speed to 1.6 and show "when in main hand...attack damage,...attack speed"? also, how can I make the item enchantable? 
    • Ok. Thanks. by the way, will this crash in any circumstances? public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { if (entity instanceof LivingEntity){ LivingEntity victim = (LivingEntity) entity; if(!victim.isDeadOrDying() && victim.getHealth()>0){ victim.setHealth(0); return true; } } return false; }  
    • You shouldn't be extracting the mod .jar, just place it in your mods folder.
  • Topics

×
×
  • Create New...

Important Information

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