Jump to content

[1.11] Destroy dropped item and a question about event handlers


Recommended Posts

Posted (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 by Frost2779
Posted (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 by Jay Avery
Posted (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 by Frost2779
Posted

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.

Posted
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)

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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