87 lines
4.8 KiB
Diff
87 lines
4.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: lexikiq <noellekiq@gmail.com>
|
|
Date: Sat, 19 Jun 2021 01:14:13 -0400
|
|
Subject: [PATCH] Add PlayerUseRespawnAnchorEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
index af4eb4a8814491afef449a2874521636957d7557..93fae52a7531e1697e4fa63c82aef6ef24d0fb25 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/RespawnAnchorBlock.java
|
|
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList;
|
|
import com.google.common.collect.ImmutableList.Builder;
|
|
import java.util.Optional;
|
|
import java.util.Random;
|
|
+import me.lexikiq.event.player.PlayerUseRespawnAnchorEvent; // Parchment
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.Vec3i;
|
|
@@ -52,33 +53,51 @@ public class RespawnAnchorBlock extends Block {
|
|
@Override
|
|
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
|
ItemStack itemStack = player.getItemInHand(hand);
|
|
+
|
|
+ // Parchment start -- PlayerUseRespawnAnchorEvent
|
|
+ org.bukkit.entity.Player bukkitPlayer = player.getBukkitEntity() instanceof org.bukkit.entity.Player ? (org.bukkit.entity.Player) player.getBukkitEntity() : null;
|
|
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(world, pos);
|
|
+ PlayerUseRespawnAnchorEvent.RespawnAnchorResult result;
|
|
if (hand == InteractionHand.MAIN_HAND && !isRespawnFuel(itemStack) && isRespawnFuel(player.getItemInHand(InteractionHand.OFF_HAND))) {
|
|
return InteractionResult.PASS;
|
|
} else if (isRespawnFuel(itemStack) && canBeCharged(state)) {
|
|
+ result = PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE;
|
|
+ } else if (state.getValue(CHARGE) == 0) {
|
|
+ result = PlayerUseRespawnAnchorEvent.RespawnAnchorResult.NOTHING;
|
|
+ } else if (!canSetSpawn(world) && !world.isClientSide) {
|
|
+ result = PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE;
|
|
+ } else if (!world.isClientSide) {
|
|
+ result = PlayerUseRespawnAnchorEvent.RespawnAnchorResult.SET_SPAWN;
|
|
+ } else {
|
|
+ return InteractionResult.SUCCESS;
|
|
+ }
|
|
+
|
|
+ if (bukkitPlayer != null) {
|
|
+ PlayerUseRespawnAnchorEvent event = new PlayerUseRespawnAnchorEvent(bukkitPlayer, block, result);
|
|
+ event.callEvent();
|
|
+ result = event.getResult();
|
|
+ }
|
|
+
|
|
+ if (result == PlayerUseRespawnAnchorEvent.RespawnAnchorResult.NOTHING) {
|
|
+ return InteractionResult.PASS;
|
|
+ } else if (result == PlayerUseRespawnAnchorEvent.RespawnAnchorResult.CHARGE) {
|
|
charge(world, pos, state);
|
|
if (!player.getAbilities().instabuild) {
|
|
itemStack.shrink(1);
|
|
}
|
|
|
|
return InteractionResult.sidedSuccess(world.isClientSide);
|
|
- } else if (state.getValue(CHARGE) == 0) {
|
|
- return InteractionResult.PASS;
|
|
- } else if (!canSetSpawn(world)) {
|
|
- if (!world.isClientSide) {
|
|
- this.explode(state, world, pos);
|
|
- }
|
|
-
|
|
- return InteractionResult.sidedSuccess(world.isClientSide);
|
|
+ } else if (result == PlayerUseRespawnAnchorEvent.RespawnAnchorResult.EXPLODE) {
|
|
+ this.explode(state, world, pos);
|
|
+ return InteractionResult.CONSUME;
|
|
} else {
|
|
- if (!world.isClientSide) {
|
|
- ServerPlayer serverPlayer = (ServerPlayer)player;
|
|
- if (serverPlayer.getRespawnDimension() != world.dimension() || !pos.equals(serverPlayer.getRespawnPosition())) {
|
|
- serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true);
|
|
- world.playSound((Player)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
- return InteractionResult.SUCCESS;
|
|
- }
|
|
+ ServerPlayer serverPlayer = (ServerPlayer)player;
|
|
+ if (serverPlayer.getRespawnDimension() != world.dimension() || !pos.equals(serverPlayer.getRespawnPosition())) {
|
|
+ serverPlayer.setRespawnPosition(world.dimension(), pos, 0.0F, false, true);
|
|
+ world.playSound((Player)null, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, SoundEvents.RESPAWN_ANCHOR_SET_SPAWN, SoundSource.BLOCKS, 1.0F, 1.0F);
|
|
+ return InteractionResult.SUCCESS;
|
|
}
|
|
-
|
|
+ // Parchment end
|
|
return InteractionResult.CONSUME;
|
|
}
|
|
}
|