Jump to content

Recommended Posts

Posted (edited)

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
Posted

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?

Posted

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.

Posted (edited)

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

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



×
×
  • Create New...

Important Information

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