Jump to content

[1.8] ItemStack from EntityItem? (FML vs. Forge)


Recommended Posts

Posted

Okay, so invastagating led me to "how to", but I don't undestand why and where to look for answers:

 

There are 2 events for picking up items, one fired before - Forge (cancellable) one after on actual pickup (FML).

 

What I don't understand is why ItemStack in FML event is not "real" (it can't get full ItemStack data).

 

Forge:

@SubscribeEvent
public void entityPickup(EntityItemPickupEvent event)
{
	ItemStack stack = event.item.getEntityItem();
	if(stack != null)
	{
		System.out.println("EntityItemPickupEvent: " + stack + "   Size: " + stack.stackSize);
	}
}

 

FML:

@SubscribeEvent
public void itemPickup(ItemPickupEvent event)
{
	ItemStack stack = event.pickedUp.getEntityItem();
	if(stack != null)
	{
		System.out.println("ItemPickupEvent: " + stack + "   Size: " + stack.stackSize);
	}
}

(NBT is too lost in FML)

 

[16:17:44] [server thread/INFO] [sTDOUT]: [x.ForgeEvents:entityPickup:38]: EntityItemPickupEvent: 1xitem.stick@0   Size: 1
[16:17:44] [server thread/INFO] [sTDOUT]: [x.FMLEvents:itemPickup:33]: ItemPickupEvent: 0xitem.stick@0   Size: 0

[16:17:57] [server thread/INFO] [sTDOUT]: [x.ForgeEvents:entityPickup:38]: EntityItemPickupEvent: 59xitem.stick@0   Size: 59
[16:17:57] [server thread/INFO] [sTDOUT]: [x.FMLEvents:itemPickup:33]: ItemPickupEvent: 0xitem.stick@0   Size: 0

[16:18:07] [server thread/INFO] [sTDOUT]: [x.ForgeEvents:entityPickup:38]: EntityItemPickupEvent: 12xitem.stick@0   Size: 12
[16:18:07] [server thread/INFO] [sTDOUT]: [x.FMLEvents:itemPickup:33]: ItemPickupEvent: 0xitem.stick@0   Size: 0

 

I was trying to figure it out, but looking at how are they called leaves me with no explanation.

 

Also, why is this passed: (EntityItem#onCollideWithPlayer)

int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup(this, entityIn, itemstack);

...if the ForgeEventFactory#onItemPickup is not actually using that ItemStack? Asking because this is literally only difference between those two events.

net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(entityIn, this);

 

Asking of pure curiosity.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Yup, that explains it.

 

vB9B5.jpg

 

This line was long enough for me to miss adding stack to inv.

if (this.delayBeforeCanPickup <= 0 && (this.owner == null || lifespan - this.age <= 200 || this.owner.equals(entityIn.getName())) && (hook == 1 || i <= 0 || entityIn.inventory.addItemStackToInventory(itemstack)))

 

*applauds*

1.7.10 is no longer supported by forge, you are on your own.

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.