Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to display a simply gui about player's thirst level. It goes from 100% to 0% within 5 minutes. The problem is, I can display it only when I click an item. I'd like to display it without any items, but didn't find the solution. The second problem is, I don't know how to kill the player. What's the correct code to do it in 1.15.2?

Here's my gui:

public class ThirstScreen extends Screen {
    MyTimer timer = new MyTimer();
    private static final int WIDTH = 192;
    private static final int HEIGHT = 192;
    private ResourceLocation GUI = new ResourceLocation(VenonatMod.MOD_ID, "textures/gui/thirst_gui.png");

    public ThirstScreen() {
        super(new StringTextComponent("Thirst"));
        MinecraftForge.EVENT_BUS.register(this);
    }


    @Override
    public boolean isPauseScreen() {
        return false;
    }

    @Override
    public void render(int mouseX, int mouseY, float partialTicks) {
        int relX = (this.width - WIDTH) / 2;
        int relY = (this.height - HEIGHT) / 2;
        this.minecraft.fontRenderer.drawString(
                    "Thirst level: " + timer.getCountdown(),
                    relX + 200,
                    relY + 150,
                    0xffffff);
    }

    @SubscribeEvent
    public void onRenderOverlayText(RenderGameOverlayEvent.Post event) {

        if (this.minecraft != null && Minecraft.getInstance().currentScreen instanceof ThirstScreen) {
            RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.minecraft.getTextureManager().bindTexture(GUI);
            int relX = (this.width - WIDTH) / 2;
            int relY = (this.height - HEIGHT) / 2;
            this.blit(relX, relY, 0, 0, WIDTH, HEIGHT);
        } else {
            MinecraftForge.EVENT_BUS.unregister(this);
        }
    }
}

 

and here's my right click action:

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        Minecraft.getInstance().displayGuiScreen(new ThirstScreen());
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

As you can see, it displays with right click on the item. What should I change to display it always?

 

And the second question about killing someone. What's the correct code to do that?

Edited by Mower

  • Author

Thanks for the answer, I can kill the player now, but I don't really understand your explanation about the hud. Could you show it on my code please?

  • Author

You mean remove this whole part? 

    @SubscribeEvent
    public void onRenderOverlayText(RenderGameOverlayEvent.Post event) {

        if (this.minecraft != null && Minecraft.getInstance().currentScreen instanceof ThirstScreen) {
            RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
            this.minecraft.getTextureManager().bindTexture(GUI);
            int relX = (this.width - WIDTH) / 2;
            int relY = (this.height - HEIGHT) / 2;
            this.blit(relX, relY, 0, 0, WIDTH, HEIGHT);
        } else {
            MinecraftForge.EVENT_BUS.unregister(this);
        }
    }

 

I don't really get how it should help. I've tried to add 

Minecraft.getInstance().displayGuiScreen(new ThirstScreen());

under my 

public class ThirstScreen extends Screen {

 

but it doesn't display it.

  • Author

Here's what I use now:

    @SubscribeEvent
    public void pickupItem(EntityItemPickupEvent event) {
        Minecraft.getInstance().displayGuiScreen(new ThirstScreen());
    }

of course this one is called only if I pick up something. So I have 2 questions: What should I use instead of EntityItemPickupEvent to always display it? And the second, how can I turn off the mouse when its being displayed?

Edited by Mower

  • Author

Can you please show it on my code? I've been sitting here for hours now but still no clue. 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.