Several bugfixes for PlayerInteractEvent (#2943)
* Don't change Result if setCanceled(false) called * Fix RightClickEmpty firing even when targeting a block or entity * Add a left click empty event * Move hook point for EntityInteractSpecific to the right place * Fix LeftClickBlock not firing clientside in creative, and clarify docs about creative
This commit is contained in:
parent
92914f82ae
commit
35cd9fe212
|
@ -184,12 +184,19 @@
|
|||
{
|
||||
this.field_71442_b.func_180511_b(blockpos, this.field_71476_x.field_178784_b);
|
||||
break;
|
||||
@@ -1476,7 +1494,7 @@
|
||||
@@ -1447,6 +1465,7 @@
|
||||
}
|
||||
|
||||
this.field_71439_g.func_184821_cY();
|
||||
+ net.minecraftforge.common.ForgeHooks.onEmptyLeftClick(this.field_71439_g, this.field_71439_g.func_184614_ca());
|
||||
}
|
||||
|
||||
this.field_71439_g.func_184609_a(EnumHand.MAIN_HAND);
|
||||
@@ -1476,7 +1495,6 @@
|
||||
switch (this.field_71476_x.field_72313_a)
|
||||
{
|
||||
case ENTITY:
|
||||
-
|
||||
+ if(!net.minecraftforge.common.ForgeHooks.onInteractEntityAt(field_71439_g, field_71476_x.field_72308_g, field_71476_x, field_71439_g.func_184586_b(enumhand), enumhand))
|
||||
if (this.field_71442_b.func_187102_a(this.field_71439_g, this.field_71476_x.field_72308_g, this.field_71476_x, this.field_71439_g.func_184586_b(enumhand), enumhand) == EnumActionResult.SUCCESS)
|
||||
{
|
||||
return;
|
||||
|
@ -198,7 +205,7 @@
|
|||
|
||||
ItemStack itemstack1 = this.field_71439_g.func_184586_b(enumhand);
|
||||
-
|
||||
+ if (itemstack1 == null) net.minecraftforge.common.ForgeHooks.onEmptyClick(this.field_71439_g, enumhand);
|
||||
+ if (itemstack1 == null && (this.field_71476_x == null || this.field_71476_x.field_72313_a == RayTraceResult.Type.MISS)) net.minecraftforge.common.ForgeHooks.onEmptyClick(this.field_71439_g, enumhand);
|
||||
if (itemstack1 != null && this.field_71442_b.func_187101_a(this.field_71439_g, this.field_71441_e, itemstack1, enumhand) == EnumActionResult.SUCCESS)
|
||||
{
|
||||
this.field_71460_t.field_78516_c.func_187460_a(enumhand);
|
||||
|
|
|
@ -50,7 +50,15 @@
|
|||
return flag;
|
||||
}
|
||||
}
|
||||
@@ -218,14 +224,17 @@
|
||||
@@ -207,6 +213,7 @@
|
||||
if (this.field_78779_k.func_77145_d())
|
||||
{
|
||||
this.field_78774_b.func_147297_a(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, p_180511_1_, p_180511_2_));
|
||||
+ if (!net.minecraftforge.common.ForgeHooks.onLeftClickBlock(this.field_78776_a.field_71439_g, p_180511_1_, p_180511_2_, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(this.field_78776_a.field_71439_g, func_78757_d() + 1)).isCanceled())
|
||||
func_178891_a(this.field_78776_a, this, p_180511_1_, p_180511_2_);
|
||||
this.field_78781_i = 5;
|
||||
}
|
||||
@@ -218,14 +225,17 @@
|
||||
}
|
||||
|
||||
this.field_78774_b.func_147297_a(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, p_180511_1_, p_180511_2_));
|
||||
|
@ -69,7 +77,7 @@
|
|||
if (flag && iblockstate.func_185903_a(this.field_78776_a.field_71439_g, this.field_78776_a.field_71439_g.field_70170_p, p_180511_1_) >= 1.0F)
|
||||
{
|
||||
this.func_187103_a(p_180511_1_);
|
||||
@@ -372,13 +381,32 @@
|
||||
@@ -372,13 +382,32 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -104,7 +112,7 @@
|
|||
}
|
||||
|
||||
if (!flag && p_187099_3_ != null && p_187099_3_.func_77973_b() instanceof ItemBlock)
|
||||
@@ -394,7 +422,7 @@
|
||||
@@ -394,7 +423,7 @@
|
||||
|
||||
this.field_78774_b.func_147297_a(new CPacketPlayerTryUseItemOnBlock(p_187099_4_, p_187099_5_, p_187099_7_, f, f1, f2));
|
||||
|
||||
|
@ -113,7 +121,7 @@
|
|||
{
|
||||
if (p_187099_3_ == null)
|
||||
{
|
||||
@@ -412,14 +440,19 @@
|
||||
@@ -412,14 +441,19 @@
|
||||
{
|
||||
int i = p_187099_3_.func_77960_j();
|
||||
int j = p_187099_3_.field_77994_a;
|
||||
|
@ -134,7 +142,7 @@
|
|||
}
|
||||
}
|
||||
else
|
||||
@@ -446,6 +479,7 @@
|
||||
@@ -446,6 +480,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -142,7 +150,7 @@
|
|||
int i = p_187101_3_.field_77994_a;
|
||||
ActionResult<ItemStack> actionresult = p_187101_3_.func_77957_a(p_187101_2_, p_187101_1_, p_187101_4_);
|
||||
ItemStack itemstack = (ItemStack)actionresult.func_188398_b();
|
||||
@@ -454,9 +488,10 @@
|
||||
@@ -454,9 +489,10 @@
|
||||
{
|
||||
p_187101_1_.func_184611_a(p_187101_4_, itemstack);
|
||||
|
||||
|
@ -154,3 +162,11 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -494,6 +530,7 @@
|
||||
this.func_78750_j();
|
||||
Vec3d vec3d = new Vec3d(p_187102_3_.field_72307_f.field_72450_a - p_187102_2_.field_70165_t, p_187102_3_.field_72307_f.field_72448_b - p_187102_2_.field_70163_u, p_187102_3_.field_72307_f.field_72449_c - p_187102_2_.field_70161_v);
|
||||
this.field_78774_b.func_147297_a(new CPacketUseEntity(p_187102_2_, p_187102_5_, vec3d));
|
||||
+ if(net.minecraftforge.common.ForgeHooks.onInteractEntityAt(p_187102_1_, p_187102_2_, p_187102_3_, p_187102_1_.func_184586_b(p_187102_5_), p_187102_5_)) return EnumActionResult.PASS;
|
||||
return this.field_78779_k == WorldSettings.GameType.SPECTATOR ? EnumActionResult.PASS : p_187102_2_.func_184199_a(p_187102_1_, vec3d, p_187102_4_, p_187102_5_);
|
||||
}
|
||||
|
||||
|
|
|
@ -987,6 +987,11 @@ public class ForgeHooks
|
|||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickEmpty(player, hand));
|
||||
}
|
||||
|
||||
public static void onEmptyLeftClick(EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player, stack));
|
||||
}
|
||||
|
||||
private static ThreadLocal<Deque<LootTableContext>> lootContext = new ThreadLocal<Deque<LootTableContext>>();
|
||||
private static LootTableContext getLootTableContext()
|
||||
{
|
||||
|
|
|
@ -182,10 +182,13 @@ public class PlayerInteractEvent extends PlayerEvent
|
|||
public void setCanceled(boolean canceled)
|
||||
{
|
||||
super.setCanceled(canceled);
|
||||
if (canceled)
|
||||
{
|
||||
useBlock = DENY;
|
||||
useItem = DENY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired on both sides before the player triggers {@link net.minecraft.item.Item#onItemRightClick}.
|
||||
|
@ -220,8 +223,12 @@ public class PlayerInteractEvent extends PlayerEvent
|
|||
* This event controls which of {@link net.minecraft.block.Block#onBlockClicked} and/or the item harvesting methods will be called
|
||||
* Canceling the event will cause none of the above noted methods to be called.
|
||||
* There are various results to this event, see the getters below.
|
||||
*
|
||||
* Note that if the event is canceled and the player holds down left mouse, the event will continue to fire.
|
||||
* This is due to how vanilla calls the left click handler methods.
|
||||
*
|
||||
* Also note that creative mode directly breaks the block without running any other logic.
|
||||
* Therefore, in creative mode, {@link #setUseBlock} and {@link #setUseItem} have no effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class LeftClickBlock extends PlayerInteractEvent
|
||||
|
@ -245,7 +252,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
|||
}
|
||||
|
||||
/**
|
||||
* @return If {@link net.minecraft.block.Block#onBlockClicked} should be called
|
||||
* @return If {@link net.minecraft.block.Block#onBlockClicked} should be called. Changing this has no effect in creative mode
|
||||
*/
|
||||
public Result getUseBlock()
|
||||
{
|
||||
|
@ -253,7 +260,7 @@ public class PlayerInteractEvent extends PlayerEvent
|
|||
}
|
||||
|
||||
/**
|
||||
* @return If the block should be attempted to be mined with the current item
|
||||
* @return If the block should be attempted to be mined with the current item. Changing this has no effect in creative mode
|
||||
*/
|
||||
public Result getUseItem()
|
||||
{
|
||||
|
@ -274,10 +281,26 @@ public class PlayerInteractEvent extends PlayerEvent
|
|||
public void setCanceled(boolean canceled)
|
||||
{
|
||||
super.setCanceled(canceled);
|
||||
if (canceled)
|
||||
{
|
||||
useBlock = DENY;
|
||||
useItem = DENY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired on the client side when the player left clicks empty space with any ItemStack.
|
||||
* The server is not aware of when the client left clicks empty space, you will need to tell the server yourself.
|
||||
* This event cannot be canceled.
|
||||
*/
|
||||
public static class LeftClickEmpty extends PlayerInteractEvent
|
||||
{
|
||||
public LeftClickEmpty(EntityPlayer player, ItemStack stack)
|
||||
{
|
||||
super(player, EnumHand.MAIN_HAND, stack, new BlockPos(player), null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The hand involved in this interaction. Will never be null.
|
||||
|
|
Loading…
Reference in New Issue