Skip to content

Commit

Permalink
Add an inset to out of bounds position clamping
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jul 8, 2024
1 parent ae917da commit aac127a
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import xyz.nucleoid.plasmid.game.event.GameActivityEvents;

public class PlayerEntry implements GameActivityEvents.Tick {
private static final double OUT_OF_BOUNDS_CLAMP_INSET = 0.03;

private final VolleyballActivePhase phase;
private final ServerPlayerEntity player;
private final TeamEntry team;
Expand All @@ -30,9 +32,9 @@ public void onTick() {
BlockPos min = area.getBounds().min();
BlockPos max = area.getBounds().max();

double x = MathHelper.clamp(pos.getX(), min.getX(), max.getX() + 1);
double y = MathHelper.clamp(pos.getY(), min.getY(), max.getY() + 1);
double z = MathHelper.clamp(pos.getZ(), min.getZ(), max.getZ() + 1);
double x = clampOutOfBounds(pos.getX(), min.getX(), max.getX() + 1);
double y = clampOutOfBounds(pos.getY(), min.getY(), max.getY() + 1);
double z = clampOutOfBounds(pos.getZ(), min.getZ(), max.getZ() + 1);

player.teleport(x, y, z);
}
Expand Down Expand Up @@ -62,4 +64,12 @@ public void clearInventory() {
this.player.currentScreenHandler.sendContentUpdates();
this.player.playerScreenHandler.onContentChanged(this.player.getInventory());
}

private static double clampOutOfBounds(double value, double min, double max) {
if (value < min || value > max) {
return MathHelper.clamp(value, min + OUT_OF_BOUNDS_CLAMP_INSET, max - OUT_OF_BOUNDS_CLAMP_INSET);
}

return value;
}
}

0 comments on commit aac127a

Please sign in to comment.