Frost2779 Posted February 20, 2017 Share Posted February 20, 2017 (edited) So there is an item in my mod that I want to be destroyed whenever it is dropped onto the ground. But I can't seem to find a way to accomplish this, any ideas? Secondly I am having a problem with initializing my event handler, as it doesn't give my item to players when they respawn. Event Handler: package com.Frost2779.AWillToLive.Init; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent; @Mod.EventBusSubscriber public class EventHandler { @SubscribeEvent public void PlayerRespawnEvent(PlayerEvent.PlayerRespawnEvent event) { if (!event.player.world.isRemote) { event.player.inventory.addItemStackToInventory(new ItemStack(ModItems.fullWill)); } } } Edited February 20, 2017 by Frost2779 Quote Link to comment Share on other sites More sharing options...
Jay Avery Posted February 20, 2017 Share Posted February 20, 2017 (edited) There's ItemTossEvent, which is fired whenever a player drops an item from their inventory. If you cancel the event, the item won't spawn as an entity. Edit: although if it's your item, you could override onEntityItemUpdate to kill the entity as soon as it exists. Edited February 20, 2017 by Jay Avery Quote Link to comment Share on other sites More sharing options...
Frost2779 Posted February 20, 2017 Author Share Posted February 20, 2017 (edited) 9 minutes ago, Jay Avery said: There's ItemTossEvent, which is fired whenever a player drops an item from their inventory. If you cancel the event, the item won't spawn as an entity. Edit: although if it's your item, you could override onEntityItemUpdate to kill the entity as soon as it exists. Thanks, do you have any insight as to why my event handler isn't working? Edit: One problem is that if i kill it through onEntityItemUpdate it doesn't appear in your hand Edited February 20, 2017 by Frost2779 Quote Link to comment Share on other sites More sharing options...
Pingubro Posted February 20, 2017 Share Posted February 20, 2017 Please post your Classes where you use your EventHandler. Maybe you are just not registering your EventHandler. To achieve the functionality you want maybe look at createEntity or onEntityItemUpdate and override it in your Item Class. Quote Link to comment Share on other sites More sharing options...
Matryoshika Posted February 20, 2017 Share Posted February 20, 2017 9 hours ago, Frost2779 said: Edit: One problem is that if i kill it through onEntityItemUpdate it doesn't appear in your hand Well, of course. If you kill the entity, you destroy the itemstack, Pretty hard to appear in one's hand if it does not exist. I also believe that the PlayerRespawnEvent happens before the player has respawned, as a signal that it is about to respawn. Try and switch it out for the Clone event instead. This is where everything gets transferred from the old entity to the new one. (getOriginal = old body, getEntityPlayer = new body) Quote Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials. Link to comment Share on other sites More sharing options...
Recommended Posts
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.