Jump to content

Mower

Members
  • Posts

    9
  • Joined

  • Last visited

Mower's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  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. 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?
×
×
  • Create New...

Important Information

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