mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-12 09:51:12 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
58 lines
3.1 KiB
Diff
58 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: jmp <jasonpenilla2@me.com>
|
|
Date: Wed, 25 Nov 2020 23:20:44 -0800
|
|
Subject: [PATCH] Implement 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
|
|
index bbaf90b30b07c97321541b8fe15d47975a34161d..a7215c9b9f0f191bbfe95cb1185c99a8d21ff785 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/TargetBlock.java
|
|
@@ -1,5 +1,6 @@
|
|
package net.minecraft.world.level.block;
|
|
|
|
+import io.papermc.paper.event.block.TargetHitEvent; // Paper - Need to import because 'io' class exists in nms
|
|
import java.util.Random;
|
|
import net.minecraft.advancements.CriteriaTriggers;
|
|
import net.minecraft.core.BlockPos;
|
|
@@ -34,13 +35,17 @@ public class TargetBlock extends Block {
|
|
@Override
|
|
public void onProjectileHit(Level world, BlockState state, BlockHitResult hit, Projectile projectile) {
|
|
int i = updateRedstoneOutput((LevelAccessor) world, state, hit, (Entity) projectile);
|
|
- Entity entity = projectile.getOwner();
|
|
+ // Paper start
|
|
+ }
|
|
+ private static void awardTargetHitCriteria(Projectile iprojectile, BlockHitResult movingobjectpositionblock, int i) {
|
|
+ // Paper end
|
|
+ Entity entity = iprojectile.getOwner();
|
|
|
|
if (entity instanceof ServerPlayer) {
|
|
ServerPlayer entityplayer = (ServerPlayer) entity;
|
|
|
|
entityplayer.awardStat(Stats.TARGET_HIT);
|
|
- CriteriaTriggers.TARGET_BLOCK_HIT.trigger(entityplayer, projectile, hit.getLocation(), i);
|
|
+ CriteriaTriggers.TARGET_BLOCK_HIT.trigger(entityplayer, iprojectile, movingobjectpositionblock.getLocation(), i);
|
|
}
|
|
|
|
}
|
|
@@ -49,6 +54,20 @@ public class TargetBlock extends Block {
|
|
int i = getRedstoneStrength(movingobjectpositionblock, movingobjectpositionblock.getLocation());
|
|
int j = entity instanceof AbstractArrow ? 20 : 8;
|
|
|
|
+ // Paper start
|
|
+ if (entity instanceof Projectile) {
|
|
+ final Projectile projectile = (Projectile) entity;
|
|
+ final org.bukkit.craftbukkit.block.CraftBlock craftBlock = org.bukkit.craftbukkit.block.CraftBlock.at(world, movingobjectpositionblock.getBlockPos());
|
|
+ final org.bukkit.block.BlockFace blockFace = org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(movingobjectpositionblock.getDirection());
|
|
+ final TargetHitEvent targetHitEvent = new TargetHitEvent((org.bukkit.entity.Projectile) projectile.getBukkitEntity(), craftBlock, blockFace, i);
|
|
+ if (targetHitEvent.callEvent()) {
|
|
+ i = targetHitEvent.getSignalStrength();
|
|
+ awardTargetHitCriteria(projectile, movingobjectpositionblock, i);
|
|
+ } else {
|
|
+ return i;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
if (!world.getBlockTicks().a(movingobjectpositionblock.getBlockPos(), state.getBlock())) {
|
|
setOutputPower(world, state, i, movingobjectpositionblock.getBlockPos(), j);
|
|
}
|