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); }
}
/**