Jump to content

Custom screen overlay 1.18.2


LevelBlock

Recommended Posts

Hi, I'm trying to make a custom overlay when the player has a potion effect, like in Nausea or the pumpkin. I did some research and I need the RenderGameOverlayEvent. I've declared it but It doesn't work. Maybe i have to declare it in some other place? I actually have it on event/ModEventBus

 


@Mod.EventBusSubscriber(modid = example.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)

public class ModEventBusEvents {
    Minecraft mc = Minecraft.getInstance();
    private static final ResourceLocation IMG_LOCATION = new ResourceLocation("textures/scream/glowing.png");
    protected int screenWidth;
    protected int screenHeight;

    @SubscribeEvent
    public void HUGGYSCREAMER(RenderGameOverlayEvent event) {

        Player player = Minecraft.getInstance().player;
        //Options settings = Minecraft.getInstance().options;
        this.screenWidth = this.mc.getWindow().getGuiScaledWidth();
        this.screenHeight = this.mc.getWindow().getGuiScaledHeight();
        assert player != null;
        if (player.hasEffect(MobEffects.GLOWING)) {

            RenderSystem.disableDepthTest();
            RenderSystem.depthMask(false);
            RenderSystem.enableBlend();
            RenderSystem.blendFunc(770, 771);
            Minecraft.getInstance().getTextureManager().bindForSetup(IMG_LOCATION);
            GuiComponent.blit(event.getMatrixStack(), 0, 0, 0, 0,screenWidth ,screenHeight, 480, 270);
            RenderSystem.depthMask(true);
            RenderSystem.enableDepthTest();
         
        }
    }
    }

 

Link to comment
Share on other sites

RenderGameOverlayEvent is a runtime event not a mod specific configuration event.

So you need Bus.FORGE

The easy way to check which bus you need is whether the event implements IModBusEvent

 

It is also a client side event (it is graphics stuff), so you also need 

value = Dist.CLIENT

otherwise your mod will likely crash when loaded on a server.

Edited by warjort
  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I used the forge bus and now it works, thanks a lot.
If somebody needs it:
 

@Mod.EventBusSubscriber(modid = MYMOD.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)

public class CustomEvents implements IModBusEvent {

    static Minecraft mc = Minecraft.getInstance();
    private static final ResourceLocation IMG_LOCATION = new ResourceLocation(MYMOD.MOD_ID,"textures/scream/img.png");
    protected static int screenWidth;
    protected static int screenHeight;

    @SubscribeEvent
    public static void RenderEvent(RenderGameOverlayEvent.Post event) {

        Player player = Minecraft.getInstance().player;
        //Options settings = Minecraft.getInstance().options;
        screenWidth = mc.getWindow().getGuiScaledWidth();
        screenHeight = mc.getWindow().getGuiScaledHeight();
        assert player != null;
        if (player.hasEffect(MobEffects.GLOWING)) {

            RenderSystem.disableDepthTest();
            RenderSystem.depthMask(false);
            RenderSystem.defaultBlendFunc();
            RenderSystem.setShader(GameRenderer::getPositionTexShader);
            RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1F);
            RenderSystem.setShaderTexture(0, IMG_LOCATION);
            Tesselator tesselator = Tesselator.getInstance();
            BufferBuilder bufferbuilder = tesselator.getBuilder();
            bufferbuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
            bufferbuilder.vertex(0.0D, screenHeight, -90.0D).uv(0.0F, 1.0F).endVertex();
            bufferbuilder.vertex(screenWidth, (double) screenHeight, -90.0D).uv(1.0F, 1.0F).endVertex();
            bufferbuilder.vertex(screenWidth, 0.0D, -90.0D).uv(1.0F, 0.0F).endVertex();
            bufferbuilder.vertex(0.0D, 0.0D, -90.0D).uv(0.0F, 0.0F).endVertex();
            tesselator.end();
            RenderSystem.depthMask(true);
            RenderSystem.enableDepthTest();
            RenderSystem.setShaderColor(0.0F, 0.0F, 1.0F, 1.0F);

        }
    }}

 

Link to comment
Share on other sites

On 7/31/2022 at 5:01 AM, diesieben07 said:

Please do this.

This makes no sense.

Sorry I'm kinda new on this. I've deleted the implementation. Also I added this:

private void clientSetup(final FMLClientSetupEvent event) {

        OverlayRegistry.registerOverlayTop("custom_effect", (gui, poseStack, partialTick, screenWidth, screenHeight) -> {
            gui.setupOverlayRenderState(true, false);
        });

Not sure if it's fine, but it works. Now I have to discover how to show an animation using this.

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.