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.

Mower

Members
  • Joined

  • Last visited

  1. Could you show on my code what to do then?
  2. I have a newly registered item, which is a water flask. I'm trying to play the drinking animation and the drinking sound while right clicking on it, but it doesn't work. Because of the sound playing try, my minecraft just crashes. And the animation just doesn't work. Here's my whole Item class: package com.venonat.venonatmod.objects.items; import com.venonat.venonatmod.events.MyTimer; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.UseAction; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.SoundEvents; import net.minecraft.world.World; public class FlaskItem extends Item { MyTimer timer = MyTimer.getInstance(); Minecraft mc; boolean alreadyExecuted; public FlaskItem(Properties props) { super(props); } @Override public UseAction getUseAction(ItemStack stack){ getUseAction(stack); return UseAction.DRINK; } @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { timer.setCountdown(timer.getCountdown() + 5); if (!alreadyExecuted) { mc.player.playSound(SoundEvents.ENTITY_GENERIC_DRINK, 0.5f, 1.0f); alreadyExecuted = true; } return super.onItemRightClick(worldIn, playerIn, handIn); } } and here is my item registration: package com.venonat.venonatmod.init; import com.venonat.venonatmod.VenonatMod; import com.venonat.venonatmod.objects.items.FlaskItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.registries.ObjectHolder; @ObjectHolder(VenonatMod.MOD_ID + "flask") @Mod.EventBusSubscriber(modid = VenonatMod.MOD_ID, bus = Bus.MOD) public class ItemInit { @SubscribeEvent public static void registerItems(final RegistryEvent.Register<Item> event) { event.getRegistry().register(new FlaskItem(new Item.Properties().maxStackSize(1).group(ItemGroup.MISC)).setRegistryName("flask")); } }
  3. Can you please show it on my code? I've been sitting here for hours now but still no clue.
  4. But how else should i Write "thirst level" to the screen?
  5. 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?
  6. and how can I do that?
  7. 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.
  8. 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?
  9. Mower joined the community
  10. 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?

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.