Fixed PlayerInteractEvents not working (#5976)

This commit is contained in:
henkelmax 2019-08-02 22:44:17 +02:00 committed by LexManos
parent 9a50c208f0
commit e83e00520f
2 changed files with 73 additions and 11 deletions

View file

@ -11,7 +11,33 @@
return false;
} else {
block.func_176208_a(world, p_187103_1_, blockstate, this.field_78776_a.field_71439_g);
@@ -187,13 +189,13 @@
@@ -129,21 +131,25 @@
BlockState blockstate = this.field_78776_a.field_71441_e.func_180495_p(p_180511_1_);
this.field_78776_a.func_193032_ao().func_193294_a(this.field_78776_a.field_71441_e, p_180511_1_, blockstate, 1.0F);
this.func_225324_a(CPlayerDiggingPacket.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_).isCanceled())
func_178891_a(this.field_78776_a, this, p_180511_1_, p_180511_2_);
this.field_78781_i = 5;
} else if (!this.field_78778_j || !this.func_178893_a(p_180511_1_)) {
if (this.field_78778_j) {
this.func_225324_a(CPlayerDiggingPacket.Action.ABORT_DESTROY_BLOCK, this.field_178895_c, p_180511_2_);
}
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(this.field_78776_a.field_71439_g, p_180511_1_, p_180511_2_);
BlockState blockstate1 = this.field_78776_a.field_71441_e.func_180495_p(p_180511_1_);
this.field_78776_a.func_193032_ao().func_193294_a(this.field_78776_a.field_71441_e, p_180511_1_, blockstate1, 0.0F);
this.func_225324_a(CPlayerDiggingPacket.Action.START_DESTROY_BLOCK, p_180511_1_, p_180511_2_);
boolean flag = !blockstate1.func_196958_f();
if (flag && this.field_78770_f == 0.0F) {
+ if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY)
blockstate1.func_196942_a(this.field_78776_a.field_71441_e, p_180511_1_, this.field_78776_a.field_71439_g);
}
+ if (event.getUseItem() == net.minecraftforge.eventbus.api.Event.Result.DENY) return true;
if (flag && blockstate1.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_);
} else {
@@ -187,13 +193,13 @@
return true;
} else if (this.func_178893_a(p_180512_1_)) {
BlockState blockstate = this.field_78776_a.field_71441_e.func_180495_p(p_180512_1_);
@ -27,7 +53,7 @@
this.field_78776_a.func_147118_V().func_147682_a(new SimpleSound(soundtype.func_185846_f(), SoundCategory.NEUTRAL, (soundtype.func_185843_a() + 1.0F) / 8.0F, soundtype.func_185847_b() * 0.5F, p_180512_1_));
}
@@ -217,7 +219,8 @@
@@ -217,7 +223,8 @@
}
public float func_78757_d() {
@ -37,7 +63,7 @@
}
public void func_78765_e() {
@@ -234,7 +237,7 @@
@@ -234,7 +241,7 @@
ItemStack itemstack = this.field_78776_a.field_71439_g.func_184614_ca();
boolean flag = this.field_85183_f.func_190926_b() && itemstack.func_190926_b();
if (!this.field_85183_f.func_190926_b() && !itemstack.func_190926_b()) {
@ -46,7 +72,20 @@
}
return p_178893_1_.equals(this.field_178895_c) && flag;
@@ -298,11 +301,14 @@
@@ -257,6 +264,12 @@
return ActionResultType.FAIL;
} else {
ItemStack itemstack = p_217292_1_.func_184586_b(p_217292_3_);
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = net.minecraftforge.common.ForgeHooks
+ .onRightClickBlock(p_217292_1_, p_217292_3_, blockpos, p_217292_4_.func_216354_b());
+ if (event.isCanceled()) {
+ this.field_78774_b.func_147297_a(new CPlayerTryUseItemOnBlockPacket(p_217292_3_, p_217292_4_));
+ return event.getCancellationResult();
+ }
if (this.field_78779_k == GameType.SPECTATOR) {
this.field_78774_b.func_147297_a(new CPlayerTryUseItemOnBlockPacket(p_217292_3_, p_217292_4_));
return ActionResultType.SUCCESS;
@@ -298,11 +311,14 @@
if (p_187101_1_.func_184811_cZ().func_185141_a(itemstack.func_77973_b())) {
return ActionResultType.PASS;
} else {
@ -61,7 +100,7 @@
}
return actionresult.func_188397_a();
@@ -327,6 +333,9 @@
@@ -327,6 +343,9 @@
public ActionResultType func_187097_a(PlayerEntity p_187097_1_, Entity p_187097_2_, Hand p_187097_3_) {
this.func_78750_j();
this.field_78774_b.func_147297_a(new CUseEntityPacket(p_187097_2_, p_187097_3_));
@ -71,7 +110,7 @@
return this.field_78779_k == GameType.SPECTATOR ? ActionResultType.PASS : p_187097_1_.func_190775_a(p_187097_2_, p_187097_3_);
}
@@ -334,6 +343,9 @@
@@ -334,6 +353,9 @@
this.func_78750_j();
Vec3d vec3d = p_187102_3_.func_216347_e().func_178786_a(p_187102_2_.field_70165_t, p_187102_2_.field_70163_u, p_187102_2_.field_70161_v);
this.field_78774_b.func_147297_a(new CUseEntityPacket(p_187102_2_, p_187102_4_, vec3d));

View file

@ -18,18 +18,24 @@
this.field_73092_a.func_175715_c(this.field_73090_b.func_145782_y(), this.field_180240_f, -1);
this.field_73094_o = -1;
this.field_73088_d = false;
@@ -115,7 +115,9 @@
@@ -115,7 +115,15 @@
double d1 = this.field_73090_b.field_70163_u - ((double)p_225416_1_.func_177956_o() + 0.5D) + 1.5D;
double d2 = this.field_73090_b.field_70161_v - ((double)p_225416_1_.func_177952_p() + 0.5D);
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
- if (d3 > 36.0D) {
+ double dist = field_73090_b.func_110148_a(net.minecraft.entity.player.PlayerEntity.REACH_DISTANCE).func_111126_e() + 1;
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(field_73090_b, p_225416_1_, p_225416_3_);
+ if (event.isCanceled()) { // Restore block and te data
+ field_73090_b.field_71135_a.func_147359_a(new SPlayerDiggingPacket(p_225416_1_, field_73092_a.func_180495_p(p_225416_1_), p_225416_2_, false));
+ field_73092_a.func_184138_a(p_225416_1_, field_73092_a.func_180495_p(p_225416_1_), field_73092_a.func_180495_p(p_225416_1_), 3);
+ return;
+ }
+ dist *= dist;
+ if (d3 > dist) {
this.field_73090_b.field_71135_a.func_147359_a(new SPlayerDiggingPacket(p_225416_1_, this.field_73092_a.func_180495_p(p_225416_1_), p_225416_2_, false));
} else if (p_225416_1_.func_177956_o() >= p_225416_4_) {
this.field_73090_b.field_71135_a.func_147359_a(new SPlayerDiggingPacket(p_225416_1_, this.field_73092_a.func_180495_p(p_225416_1_), p_225416_2_, false));
@@ -145,12 +147,12 @@
@@ -145,12 +153,12 @@
this.field_73089_e = this.field_73100_i;
float f = 1.0F;
BlockState blockstate = this.field_73092_a.func_180495_p(p_225416_1_);
@ -44,7 +50,7 @@
this.func_225415_a(p_225416_1_, p_225416_2_);
} else {
this.field_73088_d = true;
@@ -203,7 +205,8 @@
@@ -203,7 +211,8 @@
public boolean func_180237_b(BlockPos p_180237_1_) {
BlockState blockstate = this.field_73092_a.func_180495_p(p_180237_1_);
@ -54,7 +60,7 @@
return false;
} else {
TileEntity tileentity = this.field_73092_a.func_175625_s(p_180237_1_);
@@ -211,25 +214,30 @@
@@ -211,25 +220,30 @@
if ((block instanceof CommandBlockBlock || block instanceof StructureBlock || block instanceof JigsawBlock) && !this.field_73090_b.func_195070_dx()) {
this.field_73092_a.func_184138_a(p_180237_1_, blockstate, blockstate, 3);
return false;
@ -92,7 +98,7 @@
return true;
}
@@ -237,6 +245,14 @@
@@ -237,12 +251,22 @@
}
}
@ -107,3 +113,20 @@
public ActionResultType func_187250_a(PlayerEntity p_187250_1_, World p_187250_2_, ItemStack p_187250_3_, Hand p_187250_4_) {
if (this.field_73091_c == GameType.SPECTATOR) {
return ActionResultType.PASS;
} else if (p_187250_1_.func_184811_cZ().func_185141_a(p_187250_3_.func_77973_b())) {
return ActionResultType.PASS;
} else {
+ ActionResultType cancelResult = net.minecraftforge.common.ForgeHooks.onItemRightClick(p_187250_1_, p_187250_4_);
+ if (cancelResult != null) return cancelResult;
int i = p_187250_3_.func_190916_E();
int j = p_187250_3_.func_77952_i();
ActionResult<ItemStack> actionresult = p_187250_3_.func_77957_a(p_187250_2_, p_187250_1_, p_187250_4_);
@@ -291,6 +315,8 @@
return ActionResultType.SUCCESS;
} else if (!p_219441_3_.func_190926_b() && !p_219441_1_.func_184811_cZ().func_185141_a(p_219441_3_.func_77973_b())) {
ItemUseContext itemusecontext = new ItemUseContext(p_219441_1_, p_219441_4_, p_219441_5_);
+ net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock event = net.minecraftforge.common.ForgeHooks.onRightClickBlock(p_219441_1_, p_219441_4_, blockpos, p_219441_5_.func_216354_b());
+ if (event.isCanceled()) return event.getCancellationResult();
if (this.func_73083_d()) {
int i = p_219441_3_.func_190916_E();
ActionResultType actionresulttype = p_219441_3_.func_196084_a(itemusecontext);