Posted March 12, 20214 yr So, I have this code. What I wanna do is that when the item is in my inventory, the player is set on fire. It isn't working... Any Idea on what is the problem (Eclipse shows me no problem) I almost forgot to say, I used ACATIA_BUTTON just to test and I'm kinda new at this. package com.riceandcheese.jademod.common.items; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraftforge.event.TickEvent.PlayerTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; public class SpecialItem4 extends Item { public SpecialItem4(Properties properties) { super(properties); } @SubscribeEvent public void onTickPlayerEvent(PlayerTickEvent event){ if(event.player instanceof PlayerEntity){ PlayerEntity player = (PlayerEntity) event.player; if(player.inventory.hasItemStack(Items.ACACIA_BUTTON.getDefaultInstance())) { player.forceFireTicks(21); } } } } Edited March 12, 20214 yr by RiceAndCheese
March 12, 20214 yr https://mcforge.readthedocs.io/en/latest/events/intro/ you shouldn't be putting event handlers in Item classes, but in specific event handler classes (separation of concern). your event handlers then should be registered to the Event Bus, so that the event listeners actually fire. The linked doc page explains it further
March 12, 20214 yr Author 3 hours ago, diesieben07 said: Several things don't make sense about your code. Do you want to use an item that is not added by your mod (e.g. the acacia button)? If so, why do you have a class that extends Item then? If you want to do it for an item added by your mod (e.g. the "SpecialItem4"), why do you use an event for this? Override inventoryTick in your Item class instead. Ok so, this is my EventHandler class: package com.riceandcheese.jademod.core.event; import com.riceandcheese.jademod.Jademod; import com.riceandcheese.jademod.core.init.Iteminit; import net.minecraft.entity.player.PlayerEntity; import net.minecraftforge.event.TickEvent.PlayerTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @EventBusSubscriber(modid = Jademod.MOD_ID, bus = Bus.FORGE) public class EventHandler { @SubscribeEvent public void onTickPlayerEvent(PlayerTickEvent event){ if(event.player instanceof PlayerEntity){ PlayerEntity player = (PlayerEntity) event.player; if(player.inventory.hasItemStack(Iteminit.fire_fragment.get().getDefaultInstance())) { player.forceFireTicks(21); } } } } It's still not working (fire_fragment is the item that's gonna make it happen)
March 12, 20214 yr 12 minutes ago, RiceAndCheese said: fire_fragment is the item that's gonna make it happen 3 hours ago, diesieben07 said: If you want to do it for an item added by your mod (e.g. the "SpecialItem4"), why do you use an event for this? Override inventoryTick in your Item class instead. *Squint* Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
March 12, 20214 yr Author Worked thanks! If anyone wants the code: package com.riceandcheese.jademod.common.items; import com.riceandcheese.jademod.core.init.Iteminit; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class SpecialItem4 extends Item { public SpecialItem4(Properties properties) { super(properties); } @Override public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { if(entityIn instanceof PlayerEntity){ PlayerEntity player = (PlayerEntity) entityIn; if(player.inventory.hasItemStack(Iteminit.fire_fragment.get().getDefaultInstance())) { player.forceFireTicks(30); } } super.inventoryTick(stack, worldIn, entityIn, itemSlot, isSelected); } }
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.