From 094200e687135df77096341e3d56860d96d08384 Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 25 Jul 2022 16:20:44 -0700 Subject: [PATCH] Fix PlayerEvent.BreakSpeed using magic block position to signify invalid position. Closes #8906 --- .../event/entity/player/PlayerEvent.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java b/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java index 9e3cdc3e15..c4e6fc2e2b 100644 --- a/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java @@ -6,6 +6,7 @@ package net.minecraftforge.event.entity.player; import java.io.File; +import java.util.Optional; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.item.ItemEntity; @@ -92,7 +93,7 @@ public class PlayerEvent extends LivingEvent * {@link #state} contains the block being broken.
* {@link #originalSpeed} contains the original speed at which the player broke the block.
* {@link #newSpeed} contains the newSpeed at which the player will break the block.
- * {@link #pos} contains the coordinates at which this event is occurring. Y value -1 means location is unknown.
+ * {@link #pos} contains the coordinates at which this event is occurring. Optional value.
*
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.
* If it is canceled, the player is unable to break the block.
@@ -104,25 +105,27 @@ public class PlayerEvent extends LivingEvent @Cancelable public static class BreakSpeed extends PlayerEvent { + private static final BlockPos LEGACY_UNKNOWN = new BlockPos(0, -1, 0); private final BlockState state; private final float originalSpeed; private float newSpeed = 0.0f; - private final BlockPos pos; // Y position of -1 notes unknown location + private final Optional pos; // Y position of -1 notes unknown location - public BreakSpeed(Player player, BlockState state, float original, BlockPos pos) + public BreakSpeed(Player player, BlockState state, float original, @Nullable BlockPos pos) { super(player); this.state = state; this.originalSpeed = original; this.setNewSpeed(original); - this.pos = pos != null ? pos : new BlockPos(0, -1, 0); + this.pos = Optional.ofNullable(pos); } public BlockState getState() { return state; } public float getOriginalSpeed() { return originalSpeed; } public float getNewSpeed() { return newSpeed; } public void setNewSpeed(float newSpeed) { this.newSpeed = newSpeed; } - public BlockPos getPos() { return pos; } + public Optional getPosition() { return this.pos; } + @Deprecated(forRemoval = true, since ="1.19") public BlockPos getPos() { return pos.orElse(LEGACY_UNKNOWN); } } /**