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.

Featured Replies

Posted

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

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

  • Author
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

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.

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...

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.