Fix for the EntityItemPickupEvent having 0 count item when event is fired. (#4549)

This commit is contained in:
Draco18s authored and LexManos committed 2017-11-30 21:46:54 -08:00
1 parent b215d90589
commit ccc44956fd
4 files changed
+71 -10

No files matched your search

@@ -84,7 +84,7 @@
if (this.func_145800_j() != null)
{
@@ -358,18 +381,24 @@
@@ -358,22 +381,30 @@
{
this.func_70106_y();
}
@@ -103,14 +103,21 @@
- if (this.field_145804_b == 0 && (this.field_145802_g == null || 6000 - this.field_70292_b <= 200 || this.field_145802_g.equals(p_70100_1_.func_70005_c_())) && p_70100_1_.field_71071_by.func_70441_a(itemstack))
+ int hook = net.minecraftforge.event.ForgeEventFactory.onItemPickup(this, p_70100_1_);
+ if (hook < 0) return;
+ ItemStack clone = itemstack.func_77946_l();
+
+ if (this.field_145804_b <= 0 && (this.field_145802_g == null || lifespan - this.field_70292_b <= 200 || this.field_145802_g.equals(p_70100_1_.func_70005_c_())) && (hook == 1 || i <= 0 || p_70100_1_.field_71071_by.func_70441_a(itemstack)))
+ if (this.field_145804_b <= 0 && (this.field_145802_g == null || lifespan - this.field_70292_b <= 200 || this.field_145802_g.equals(p_70100_1_.func_70005_c_())) && (hook == 1 || i <= 0 || p_70100_1_.field_71071_by.func_70441_a(itemstack) || clone.func_190916_E() > this.func_92059_d().func_190916_E()))
{
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(p_70100_1_, this);
p_70100_1_.func_71001_a(this, i);
- p_70100_1_.func_71001_a(this, i);
+ clone.func_190920_e(clone.func_190916_E() - this.func_92059_d().func_190916_E());
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(p_70100_1_, this, clone);
if (itemstack.func_190926_b())
@@ -476,6 +505,6 @@
{
+ p_70100_1_.func_71001_a(this, i);
this.func_70106_y();
itemstack.func_190920_e(i);
}
@@ -476,6 +507,6 @@
public void func_174870_v()
{
this.func_174871_r();
@@ -583,9 +583,9 @@ public class FMLCommonHandler
bus().post(new PlayerEvent.PlayerRespawnEvent(player, endConquered));
}
public void firePlayerItemPickupEvent(EntityPlayer player, EntityItem item)
public void firePlayerItemPickupEvent(EntityPlayer player, EntityItem item, ItemStack clone)
{
bus().post(new PlayerEvent.ItemPickupEvent(player, item));
bus().post(new PlayerEvent.ItemPickupEvent(player, item, clone));
}
public void firePlayerCraftingEvent(EntityPlayer player, ItemStack crafted, IInventory craftMatrix)
@@ -35,11 +35,27 @@ public class PlayerEvent extends Event {
}
public static class ItemPickupEvent extends PlayerEvent {
public final EntityItem pickedUp;
public ItemPickupEvent(EntityPlayer player, EntityItem pickedUp)
/**
* Original EntityItem with current remaining stack size
*/
private final EntityItem originalEntity;
/**
* Clone item stack, containing the item and amount picked up
*/
private final ItemStack stack;
public ItemPickupEvent(EntityPlayer player, EntityItem entPickedUp, ItemStack stack)
{
super(player);
this.pickedUp = pickedUp;
originalEntity = entPickedUp;
this.stack = stack;
}
public ItemStack getStack() {
return stack;
}
public EntityItem getOriginalEntity() {
return originalEntity;
}
}
@@ -0,0 +1,38 @@
package net.minecraftforge.debug;
import org.apache.logging.log4j.Logger;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
@Mod(modid = PlayerItemPickupEventDebug.MODID, name = PlayerItemPickupEventDebug.NAME, version = PlayerItemPickupEventDebug.VERSION, acceptableRemoteVersions = "*")
public class PlayerItemPickupEventDebug
{
private static final boolean ENABLED = true;
public static final String MODID = "playeritempickupeventdebug";
public static final String NAME = "Player.ItemPickup Event Debug";
public static final String VERSION = "1.0.0";
private static Logger logger;
@EventHandler
public void init(FMLPreInitializationEvent event)
{
logger = event.getModLog();
if (ENABLED)
{
MinecraftForge.EVENT_BUS.register(this);
}
}
@SubscribeEvent
public void itemPickupEvent(PlayerEvent.ItemPickupEvent event)
{
logger.info("Item picked up: " + event.getStack().getDisplayName() + "x" + event.getStack().getCount());
}
}