Jump to content

How does the hotbar works?


Spyeedy

Recommended Posts

So I am wondering how the hotbar works as I have an overlay, that has been made, that I want to be connected to my GUI's slot.

Here's my code for that Overlay I was talking about:

[spoiler=Gui Overlay]

public class GuiWeaponSlots extends Gui
{
private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID + ":textures/gui/weaponSlots.png");

@SubscribeEvent(priority=EventPriority.NORMAL)
public void onRenderGameOverlay(RenderGameOverlayEvent.Post event)
{
	if (event.isCancelable() || event.type != ElementType.EXPERIENCE)
	{
		Minecraft mc = Minecraft.getMinecraft();

		ScaledResolution sr = new ScaledResolution(mc);
            int i = sr.getScaledWidth() / 2;
            ItemStack stack = mc.thePlayer.inventory.getItemStack();
            
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            mc.getTextureManager().bindTexture(texture);
		this.drawTexturedModalRect(i - 121, sr.getScaledHeight() - 22, 0, 0, 22, 22);
		this.drawTexturedModalRect(i + 101, sr.getScaledHeight() - 22, 0, 0, 22, 22);
	}
}
}

 

 

 

[spoiler=GUI (slots)]

public class GuiWeapons extends GuiContainer
{
private float xSize_lo;
private float ySize_lo;
private static ResourceLocation slot = new ResourceLocation(Reference.MOD_ID + ":textures/gui/gui_heroesWeapons.png");

public GuiWeapons(EntityPlayer player, InventoryPlayer invPlayer, InventoryWeapons invWeapons)
{
	super(new ContainerWeapons(player, invPlayer, invWeapons));
	this.xSize = 256;
	this.ySize = 146;
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
	super.drawScreen(mouseX, mouseY, partialTicks);
	this.xSize_lo = mouseX;
	this.ySize_lo = mouseY;
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
    int i = (this.width - this.xSize) / 2;
    int j = (this.height - this.ySize) / 2;
    int x = i + this.xSize / 2;
    int y = j + this.ySize / 2 + 25;
    this.mc.getTextureManager().bindTexture(slot);
        this.drawTexturedModalRect(i, j, 0, 0, xSize, ySize);
        drawEntityOnScreen(x, y, 40, (float)(i + 51) - this.xSize_lo, (float)(j + 75 - 50) - this.ySize_lo, mc.thePlayer);
}

public static void drawEntityOnScreen(int posX, int posY, int scale, float mouseX, float mouseY, EntityLivingBase ent)
    {
        GlStateManager.enableColorMaterial();
        GlStateManager.pushMatrix();
        GlStateManager.translate((float)posX, (float)posY, 50.0F);
        GlStateManager.scale((float)(-scale), (float)scale, (float)scale);
        GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
        float f = ent.renderYawOffset;
        float f1 = ent.rotationYaw;
        float f2 = ent.rotationPitch;
        float f3 = ent.prevRotationYawHead;
        float f4 = ent.rotationYawHead;
        GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F);
        RenderHelper.enableStandardItemLighting();
        GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
        ent.renderYawOffset = (float)Math.atan((double)(mouseX / 40.0F)) * 20.0F;
        ent.rotationYaw = (float)Math.atan((double)(mouseX / 40.0F)) * 40.0F;
        ent.rotationPitch = -((float)Math.atan((double)(mouseY / 40.0F))) * 20.0F;
        ent.rotationYawHead = ent.rotationYaw;
        ent.prevRotationYawHead = ent.rotationYaw;
        GlStateManager.translate(0.0F, 0.0F, 0.0F);
        RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
        rendermanager.setPlayerViewY(180.0F);
        rendermanager.setRenderShadow(false);
        rendermanager.renderEntityWithPosYaw(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
        rendermanager.setRenderShadow(true);
        ent.renderYawOffset = f;
        ent.rotationYaw = f1;
        ent.rotationPitch = f2;
        ent.prevRotationYawHead = f3;
        ent.rotationYawHead = f4;
        GlStateManager.popMatrix();
        RenderHelper.disableStandardItemLighting();
        GlStateManager.disableRescaleNormal();
        GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
        GlStateManager.disableTexture2D();
        GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
    }
}

 

 

 

Thanks in advance.

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

Since the players inventory is synced between client and server the client has the most updated data most of the time. It accesses the players inventory and displays the ItemStacks from that.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Since the players inventory is synced between client and server the client has the most updated data most of the time. It accesses the players inventory and displays the ItemStacks from that.

 

I see, but how do will my overlay know what item is in the gui slot so as to render my item in either slot 1 or slot 2?

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

The overlay needs to have access to the itemstacks, from the inventory not the gui.

 

IInventory#getStackInSlot? What method do I call to render the Item in the slot?

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

Like this

Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(getStackInSlot(), xPosition, yPosition);

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Like this

Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(getStackInSlot(), xPosition, yPosition);

For some reason, it ain't showing on the slots.

 

 

public class GuiWeaponSlots extends Gui
{
private static final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID + ":textures/gui/weaponSlots.png");

@SubscribeEvent(priority=EventPriority.NORMAL)
public void onRenderGameOverlay(RenderGameOverlayEvent.Post event)
{
	if (event.isCancelable() || event.type != ElementType.EXPERIENCE)
	{
		Minecraft mc = Minecraft.getMinecraft();
		Item item = new Item();

		ScaledResolution sr = new ScaledResolution(mc);
            int i = sr.getScaledWidth() / 2;
            InventoryWeapons invWeapons = new InventoryWeapons();
            ItemStack stack1 = invWeapons.getStackInSlot(0);
            
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            mc.getTextureManager().bindTexture(texture);
		this.drawTexturedModalRect(i - 121, sr.getScaledHeight() - 22, 0, 0, 22, 22);
		mc.getRenderItem().renderItemAndEffectIntoGUI(stack1, i - 120, sr.getScaledHeight() - 23);
		this.drawTexturedModalRect(i + 101, sr.getScaledHeight() - 22, 0, 0, 22, 22);
	}
}
}

 

 

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

Q: why are you creating a new Item here?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I'm wondering, are the ElementTypes arranged in a particular order? If so, which is the starting and what order are they arranged in?

@Cancelable
public class RenderGameOverlayEvent extends Event
{
    public static enum ElementType
    {
        ALL,
        HELMET,
        PORTAL,
        CROSSHAIRS,
        BOSSHEALTH,
        ARMOR,
        HEALTH,
        FOOD,
        AIR,
        HOTBAR,
        EXPERIENCE,
        TEXT,
        HEALTHMOUNT,
        JUMPBAR,
        CHAT,
        PLAYER_LIST,
        DEBUG
    }

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

I'm wondering, are the ElementTypes arranged in a particular order? If so, which is the starting and what order are they arranged in?

 

Look for usages of one in your IDE, then look for usages of the method you find. This will lead you to

GuiIngameForge#renderGameOverlay

, which calls the methods that fire

RenderGameOverlayEvent

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.



×
×
  • Create New...

Important Information

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