mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
Fixes for PlayerDestroyItemEvent being called with empty itemstacks. (#3728)
This commit is contained in:
1 parent
7976ac4a2b
commit
c6f181dcb2
3 files changed
+51
-40
No files matched your search
@@ -197,15 +197,22 @@
|
||||
if (this.func_180431_b(p_70097_1_))
|
||||
{
|
||||
return false;
|
||||
@@ -1006,6 +1074,7 @@
|
||||
@@ -1000,12 +1068,14 @@
|
||||
{
|
||||
if (p_184590_1_ >= 3.0F && this.field_184627_bm.func_77973_b() == Items.field_185159_cQ)
|
||||
{
|
||||
+ ItemStack copyBeforeUse = this.field_184627_bm.func_77946_l();
|
||||
int i = 1 + MathHelper.func_76141_d(p_184590_1_);
|
||||
this.field_184627_bm.func_77972_a(i, this);
|
||||
|
||||
if (this.field_184627_bm.func_190926_b())
|
||||
{
|
||||
EnumHand enumhand = this.func_184600_cs();
|
||||
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, this.field_184627_bm, enumhand);
|
||||
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, copyBeforeUse, enumhand);
|
||||
|
||||
if (enumhand == EnumHand.MAIN_HAND)
|
||||
{
|
||||
@@ -1041,7 +1110,10 @@
|
||||
@@ -1041,7 +1111,10 @@
|
||||
{
|
||||
if (!this.func_180431_b(p_70665_1_))
|
||||
{
|
||||
@@ -217,7 +224,7 @@
|
||||
p_70665_2_ = this.func_70672_c(p_70665_1_, p_70665_2_);
|
||||
float f = p_70665_2_;
|
||||
p_70665_2_ = Math.max(p_70665_2_ - this.func_110139_bj(), 0.0F);
|
||||
@@ -1111,6 +1183,8 @@
|
||||
@@ -1111,6 +1184,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -226,7 +233,7 @@
|
||||
ItemStack itemstack = this.func_184586_b(p_190775_2_);
|
||||
ItemStack itemstack1 = itemstack.func_190926_b() ? ItemStack.field_190927_a : itemstack.func_77946_l();
|
||||
|
||||
@@ -1120,7 +1194,10 @@
|
||||
@@ -1120,7 +1195,10 @@
|
||||
{
|
||||
itemstack.func_190920_e(itemstack1.func_190916_E());
|
||||
}
|
||||
@@ -238,7 +245,7 @@
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
else
|
||||
@@ -1136,6 +1213,7 @@
|
||||
@@ -1136,6 +1214,7 @@
|
||||
{
|
||||
if (itemstack.func_190926_b() && !this.field_71075_bZ.field_75098_d)
|
||||
{
|
||||
@@ -246,7 +253,7 @@
|
||||
this.func_184611_a(p_190775_2_, ItemStack.field_190927_a);
|
||||
}
|
||||
|
||||
@@ -1161,6 +1239,7 @@
|
||||
@@ -1161,6 +1240,7 @@
|
||||
|
||||
public void func_71059_n(Entity p_71059_1_)
|
||||
{
|
||||
@@ -254,7 +261,7 @@
|
||||
if (p_71059_1_.func_70075_an())
|
||||
{
|
||||
if (!p_71059_1_.func_85031_j(this))
|
||||
@@ -1333,11 +1412,13 @@
|
||||
@@ -1333,10 +1413,12 @@
|
||||
|
||||
if (!itemstack1.func_190926_b() && entity instanceof EntityLivingBase)
|
||||
{
|
||||
@@ -263,12 +270,11 @@
|
||||
|
||||
if (itemstack1.func_190926_b())
|
||||
{
|
||||
this.func_184611_a(EnumHand.MAIN_HAND, ItemStack.field_190927_a);
|
||||
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, beforeHitCopy, EnumHand.MAIN_HAND);
|
||||
this.func_184611_a(EnumHand.MAIN_HAND, ItemStack.field_190927_a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1443,6 +1524,8 @@
|
||||
@@ -1443,6 +1525,8 @@
|
||||
|
||||
public EntityPlayer.SleepResult func_180469_a(BlockPos p_180469_1_)
|
||||
{
|
||||
@@ -277,7 +283,7 @@
|
||||
EnumFacing enumfacing = (EnumFacing)this.field_70170_p.func_180495_p(p_180469_1_).func_177229_b(BlockHorizontal.field_185512_D);
|
||||
|
||||
if (!this.field_70170_p.field_72995_K)
|
||||
@@ -1484,8 +1567,9 @@
|
||||
@@ -1484,8 +1568,9 @@
|
||||
|
||||
this.func_70105_a(0.2F, 0.2F);
|
||||
|
||||
@@ -289,7 +295,7 @@
|
||||
float f1 = 0.5F + (float)enumfacing.func_82601_c() * 0.4F;
|
||||
float f = 0.5F + (float)enumfacing.func_82599_e() * 0.4F;
|
||||
this.func_175139_a(enumfacing);
|
||||
@@ -1532,13 +1616,14 @@
|
||||
@@ -1532,13 +1617,14 @@
|
||||
|
||||
public void func_70999_a(boolean p_70999_1_, boolean p_70999_2_, boolean p_70999_3_)
|
||||
{
|
||||
@@ -307,7 +313,7 @@
|
||||
|
||||
if (blockpos == null)
|
||||
{
|
||||
@@ -1547,6 +1632,10 @@
|
||||
@@ -1547,6 +1633,10 @@
|
||||
|
||||
this.func_70107_b((double)((float)blockpos.func_177958_n() + 0.5F), (double)((float)blockpos.func_177956_o() + 0.1F), (double)((float)blockpos.func_177952_p() + 0.5F));
|
||||
}
|
||||
@@ -318,7 +324,7 @@
|
||||
|
||||
this.field_71083_bS = false;
|
||||
|
||||
@@ -1565,15 +1654,16 @@
|
||||
@@ -1565,15 +1655,16 @@
|
||||
|
||||
private boolean func_175143_p()
|
||||
{
|
||||
@@ -338,7 +344,7 @@
|
||||
{
|
||||
if (!p_180467_2_)
|
||||
{
|
||||
@@ -1588,16 +1678,17 @@
|
||||
@@ -1588,16 +1679,17 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -359,7 +365,7 @@
|
||||
|
||||
switch (enumfacing)
|
||||
{
|
||||
@@ -1637,16 +1728,24 @@
|
||||
@@ -1637,16 +1729,24 @@
|
||||
|
||||
public BlockPos func_180470_cg()
|
||||
{
|
||||
@@ -386,7 +392,7 @@
|
||||
if (p_180473_1_ != null)
|
||||
{
|
||||
this.field_71077_c = p_180473_1_;
|
||||
@@ -1841,6 +1940,10 @@
|
||||
@@ -1841,6 +1941,10 @@
|
||||
|
||||
super.func_180430_e(p_180430_1_, p_180430_2_);
|
||||
}
|
||||
@@ -397,7 +403,7 @@
|
||||
}
|
||||
|
||||
protected void func_71061_d_()
|
||||
@@ -2041,6 +2144,18 @@
|
||||
@@ -2041,6 +2145,18 @@
|
||||
this.field_175152_f = p_71049_1_.field_175152_f;
|
||||
this.field_71078_a = p_71049_1_.field_71078_a;
|
||||
this.func_184212_Q().func_187227_b(field_184827_bp, p_71049_1_.func_184212_Q().func_187225_a(field_184827_bp));
|
||||
@@ -416,7 +422,7 @@
|
||||
}
|
||||
|
||||
protected boolean func_70041_e_()
|
||||
@@ -2145,7 +2260,10 @@
|
||||
@@ -2145,7 +2261,10 @@
|
||||
|
||||
public ITextComponent func_145748_c_()
|
||||
{
|
||||
@@ -428,7 +434,7 @@
|
||||
itextcomponent.func_150256_b().func_150241_a(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + this.func_70005_c_() + " "));
|
||||
itextcomponent.func_150256_b().func_150209_a(this.func_174823_aP());
|
||||
itextcomponent.func_150256_b().func_179989_a(this.func_70005_c_());
|
||||
@@ -2154,7 +2272,7 @@
|
||||
@@ -2154,7 +2273,7 @@
|
||||
|
||||
public float func_70047_e()
|
||||
{
|
||||
@@ -437,7 +443,7 @@
|
||||
|
||||
if (this.func_70608_bn())
|
||||
{
|
||||
@@ -2370,6 +2488,168 @@
|
||||
@@ -2370,6 +2489,168 @@
|
||||
return this.field_71075_bZ.field_75098_d && this.func_70003_b(2, "");
|
||||
}
|
||||
|
||||
|
||||
+15
-11
@@ -134,7 +134,7 @@
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -266,53 +301,40 @@
|
||||
@@ -266,53 +301,41 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -182,6 +182,7 @@
|
||||
if (!itemstack1.func_190926_b())
|
||||
{
|
||||
itemstack1.func_179548_a(this.field_73092_a, iblockstate, p_180237_1_, this.field_73090_b);
|
||||
+ if (itemstack1.func_190926_b()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.field_73090_b, itemstack2, EnumHand.MAIN_HAND);
|
||||
}
|
||||
|
||||
+ flag1 = this.removeBlock(p_180237_1_, flag);
|
||||
@@ -199,7 +200,7 @@
|
||||
return flag1;
|
||||
}
|
||||
}
|
||||
@@ -330,8 +352,11 @@
|
||||
@@ -330,8 +353,11 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -211,15 +212,15 @@
|
||||
ActionResult<ItemStack> actionresult = p_187250_3_.func_77957_a(p_187250_2_, p_187250_1_, p_187250_4_);
|
||||
ItemStack itemstack = (ItemStack)actionresult.func_188398_b();
|
||||
|
||||
@@ -360,6 +385,7 @@
|
||||
@@ -359,6 +385,7 @@
|
||||
|
||||
if (itemstack.func_190926_b())
|
||||
{
|
||||
p_187250_1_.func_184611_a(p_187250_4_, ItemStack.field_190927_a);
|
||||
+ net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(p_187250_1_, copyBeforeUse, p_187250_4_);
|
||||
p_187250_1_.func_184611_a(p_187250_4_, ItemStack.field_190927_a);
|
||||
}
|
||||
|
||||
if (!p_187250_1_.func_184587_cr())
|
||||
@@ -404,13 +430,23 @@
|
||||
@@ -404,13 +431,23 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -246,7 +247,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,14 +474,20 @@
|
||||
@@ -438,14 +475,22 @@
|
||||
{
|
||||
int j = p_187251_3_.func_77960_j();
|
||||
int i = p_187251_3_.func_190916_E();
|
||||
@@ -260,14 +261,17 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
- return p_187251_3_.func_179546_a(p_187251_1_, p_187251_2_, p_187251_5_, p_187251_4_, p_187251_6_, p_187251_7_, p_187251_8_, p_187251_9_);
|
||||
+ if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|
||||
+ || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW)
|
||||
return p_187251_3_.func_179546_a(p_187251_1_, p_187251_2_, p_187251_5_, p_187251_4_, p_187251_6_, p_187251_7_, p_187251_8_, p_187251_9_);
|
||||
+ else return result;
|
||||
+ || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
|
||||
+ ItemStack copyBeforeUse = p_187251_3_.func_77946_l();
|
||||
+ result = p_187251_3_.func_179546_a(p_187251_1_, p_187251_2_, p_187251_5_, p_187251_4_, p_187251_6_, p_187251_7_, p_187251_8_, p_187251_9_);
|
||||
+ if (p_187251_3_.func_190926_b()) net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(p_187251_1_, copyBeforeUse, p_187251_4_);
|
||||
+ } return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,4 +497,13 @@
|
||||
@@ -455,4 +500,13 @@
|
||||
{
|
||||
this.field_73092_a = p_73080_1_;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ package net.minecraftforge.event.entity.player;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock;
|
||||
import net.minecraft.network.play.client.CPacketPlayerTryUseItem;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.management.PlayerInteractionManager;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -44,13 +42,16 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* PlayerDestroyItemEvent is fired when a player destroys an item.<br>
|
||||
* This event is fired whenever a player destroys an item in
|
||||
* {@link PlayerControllerMP#processRightClick(EntityPlayer, World, ItemStack, EnumHand)},
|
||||
* {@link PlayerControllerMP#processRightClickBlock(EntityPlayerSP, WorldClient, ItemStack, BlockPos, EnumFacing, Vec3d, EnumHand)},
|
||||
* {@link PlayerControllerMP#onPlayerDestroyBlock(BlockPos)},
|
||||
* {@link PlayerControllerMP#processRightClick(EntityPlayer, World, EnumHand)},
|
||||
* {@link PlayerControllerMP#processRightClickBlock(EntityPlayerSP, WorldClient, BlockPos, EnumFacing, Vec3d, EnumHand)},
|
||||
* {@link EntityPlayer#attackTargetEntityWithCurrentItem(Entity)},
|
||||
* {@link EntityPlayer#damageShield(float)},
|
||||
* {@link EntityPlayer#interactOn(Entity, EnumHand)},
|
||||
* {@link ForgeHooks#getContainerItem(ItemStack)},
|
||||
* {@link PlayerInteractionManager#processRightClick(EntityPlayer, World, ItemStack, EnumHand)},
|
||||
* {@link NetHandlerPlayServer#processPlayerBlockPlacement(CPacketPlayerTryUseItem)}
|
||||
* and {@link NetHandlerPlayServer#processRightClickBlock(CPacketPlayerTryUseItemOnBlock)}.<br>
|
||||
* {@link PlayerInteractionManager#processRightClickBlock(EntityPlayer, World, ItemStack, EnumHand, BlockPos, EnumFacing, float, float, float)}
|
||||
* and {@link PlayerInteractionManager#tryHarvestBlock(BlockPos)}.<br>
|
||||
* <br>
|
||||
* {@link #original} contains the original ItemStack before the item was destroyed. <br>
|
||||
* (@link #hand) contains the hand that the current item was held in.<br>
|
||||
|
||||
Reference in new issue
Block a user