mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 11:42:55 +01:00
Fix hit criteria advancement triggered before changing state (#10409)
* Fix hit criteria advancement being triggered before changing block state. * Rebase --------- Co-authored-by: Bjarne Koll <lynxplay101@gmail.com>
This commit is contained in:
parent
46d462b83e
commit
f061e76e1f
1 changed files with 14 additions and 3 deletions
|
@ -5,7 +5,7 @@ Subject: [PATCH] Add TargetHitEvent
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/level/block/TargetBlock.java b/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
diff --git a/src/main/java/net/minecraft/world/level/block/TargetBlock.java b/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
||||||
index 02f6d5b523c3d4185a68adb419b2710768ed249f..da473a8b34e39cecf63fab8f7c4f77d485e5753b 100644
|
index 02f6d5b523c3d4185a68adb419b2710768ed249f..4ae14ee74a83c8b12ac2e3475863e6d77979af0a 100644
|
||||||
--- a/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
--- a/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
||||||
+++ b/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
+++ b/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
||||||
@@ -42,6 +42,10 @@ public class TargetBlock extends Block {
|
@@ -42,6 +42,10 @@ public class TargetBlock extends Block {
|
||||||
|
@ -19,11 +19,12 @@ index 02f6d5b523c3d4185a68adb419b2710768ed249f..da473a8b34e39cecf63fab8f7c4f77d4
|
||||||
if (projectile.getOwner() instanceof ServerPlayer serverPlayer) {
|
if (projectile.getOwner() instanceof ServerPlayer serverPlayer) {
|
||||||
serverPlayer.awardStat(Stats.TARGET_HIT);
|
serverPlayer.awardStat(Stats.TARGET_HIT);
|
||||||
CriteriaTriggers.TARGET_BLOCK_HIT.trigger(serverPlayer, projectile, hit.getLocation(), i);
|
CriteriaTriggers.TARGET_BLOCK_HIT.trigger(serverPlayer, projectile, hit.getLocation(), i);
|
||||||
@@ -51,6 +55,20 @@ public class TargetBlock extends Block {
|
@@ -51,10 +55,31 @@ public class TargetBlock extends Block {
|
||||||
private static int updateRedstoneOutput(LevelAccessor world, BlockState state, BlockHitResult hitResult, Entity entity) {
|
private static int updateRedstoneOutput(LevelAccessor world, BlockState state, BlockHitResult hitResult, Entity entity) {
|
||||||
int i = getRedstoneStrength(hitResult, hitResult.getLocation());
|
int i = getRedstoneStrength(hitResult, hitResult.getLocation());
|
||||||
int j = entity instanceof AbstractArrow ? 20 : 8;
|
int j = entity instanceof AbstractArrow ? 20 : 8;
|
||||||
+ // Paper start - Add TargetHitEvent
|
+ // Paper start - Add TargetHitEvent
|
||||||
|
+ boolean shouldAward = false;
|
||||||
+ if (entity instanceof Projectile) {
|
+ if (entity instanceof Projectile) {
|
||||||
+ final Projectile projectile = (Projectile) entity;
|
+ final Projectile projectile = (Projectile) entity;
|
||||||
+ final org.bukkit.craftbukkit.block.CraftBlock craftBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, hitResult.getBlockPos());
|
+ final org.bukkit.craftbukkit.block.CraftBlock craftBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, hitResult.getBlockPos());
|
||||||
|
@ -31,7 +32,7 @@ index 02f6d5b523c3d4185a68adb419b2710768ed249f..da473a8b34e39cecf63fab8f7c4f77d4
|
||||||
+ final io.papermc.paper.event.block.TargetHitEvent targetHitEvent = new io.papermc.paper.event.block.TargetHitEvent((org.bukkit.entity.Projectile) projectile.getBukkitEntity(), craftBlock, blockFace, i);
|
+ final io.papermc.paper.event.block.TargetHitEvent targetHitEvent = new io.papermc.paper.event.block.TargetHitEvent((org.bukkit.entity.Projectile) projectile.getBukkitEntity(), craftBlock, blockFace, i);
|
||||||
+ if (targetHitEvent.callEvent()) {
|
+ if (targetHitEvent.callEvent()) {
|
||||||
+ i = targetHitEvent.getSignalStrength();
|
+ i = targetHitEvent.getSignalStrength();
|
||||||
+ awardTargetHitCriteria(projectile, hitResult, i);
|
+ shouldAward = true;
|
||||||
+ } else {
|
+ } else {
|
||||||
+ return i;
|
+ return i;
|
||||||
+ }
|
+ }
|
||||||
|
@ -40,3 +41,13 @@ index 02f6d5b523c3d4185a68adb419b2710768ed249f..da473a8b34e39cecf63fab8f7c4f77d4
|
||||||
if (!world.getBlockTicks().hasScheduledTick(hitResult.getBlockPos(), state.getBlock())) {
|
if (!world.getBlockTicks().hasScheduledTick(hitResult.getBlockPos(), state.getBlock())) {
|
||||||
setOutputPower(world, state, i, hitResult.getBlockPos(), j);
|
setOutputPower(world, state, i, hitResult.getBlockPos(), j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ // Paper start - Award Hit Criteria after Block Update
|
||||||
|
+ if (shouldAward) {
|
||||||
|
+ awardTargetHitCriteria((Projectile) entity, hitResult, i);
|
||||||
|
+ }
|
||||||
|
+ // Paper end - Award Hit Criteria after Block Update
|
||||||
|
+
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue