Posted February 25, 20205 yr I'm trying to draw an overlay over one of the hotbar icons whenever a specific condition is met (e.g. you're holding a stick and you're pointing it to a block). So I'm listening to the RenderGameOverlayEvent.Post event, checking if the event type is HOTBAR, and then drawing the overlay if needed: Spoiler package com.example.examplemod; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.gui.AbstractGui; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.RayTraceContext; import net.minecraft.util.math.RayTraceContext.BlockMode; import net.minecraft.util.math.RayTraceContext.FluidMode; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult.Type; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber(modid="examplemod", value=Dist.CLIENT) public class ClientEventHandler { @SubscribeEvent public static void renderGameOverlay(RenderGameOverlayEvent.Post event) { if(event.getType() == ElementType.HOTBAR) { Minecraft mc = Minecraft.getInstance(); ClientPlayerEntity player = mc.player; World world = player.getEntityWorld(); int held = player.inventory.currentItem; if(held < 0 || held >= player.inventory.mainInventory.size()) return; ItemStack stack = player.inventory.mainInventory.get(held); if(!stack.isEmpty() && stack.getItem() == Items.STICK) { String textureToUse = "item_not_bound"; double eyeHeight = player.getEyeHeight(); Vec3d lookVec = new Vec3d((player.getPosition().getX() + (player.getLookVec().x * 5)), ((eyeHeight + player.getPosition().getY()) + (player.getLookVec().y * 5)), (player.getPosition().getZ() + (player.getLookVec().z * 5))); RayTraceResult mop = world.rayTraceBlocks(new RayTraceContext(new Vec3d(player.getPosition().getX(), player.getPosition().getY() + player.getEyeHeight(), player.getPosition().getZ()), lookVec, BlockMode.OUTLINE, FluidMode.NONE, player)); if(mop != null && mop.getType() == Type.BLOCK) { Minecraft.getInstance().textureManager.bindTexture(new ResourceLocation("examplemod", "textures/gui/" + textureToUse + ".png")); AbstractGui.blit(Minecraft.getInstance().func_228018_at_().getScaledWidth() / 2 - 90 + held * 20 + 2, Minecraft.getInstance().func_228018_at_().getScaledHeight() - 16 - 3, 0, 0, 16, 16, 16, 16); } } } } } This class above is the only one needed to reproduce the issue with the ExampleMod included in Forge 31.1.16 MDK However, the overlay gets drawn behind the hotbar, as it the hotbar was being rendered after it. Check this clip: https://imgur.com/a/HJCtrnM Using a different event type like ALL, which gets posted to the event bus later in time, seems to be a workaround in Forge 31.0.14, but in Forge 31.1.16 it still fails, though differently (the overlay renders correctly at first, but it eventually goes behind the hotbar item icon). This same piece of code works fine in MC 1.14.4, and checking briefly (and with my very limited knowledge) the ForgeIngameGui file, I don't see why this is failing. Am I missing anything, or is it a Forge bug? Thanks
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.