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?