allow disabling of y limit (default disabled lol)

This commit is contained in:
Virt 2025-04-04 11:55:54 +02:00
commit 042b089712
3 changed files with 21 additions and 7 deletions

View file

@ -154,6 +154,8 @@ public class ServerConfig implements CustomFile<ServerConfig> {
} }
public static class YDifferenceLimit { public static class YDifferenceLimit {
@SerializedName("enabled")
private boolean enabled = false;
@SerializedName("above") @SerializedName("above")
private Double above = 1.0; private Double above = 1.0;
@SerializedName("below") @SerializedName("below")
@ -162,14 +164,24 @@ public class ServerConfig implements CustomFile<ServerConfig> {
public YDifferenceLimit() { public YDifferenceLimit() {
} }
public YDifferenceLimit(Double above, Double below) { public YDifferenceLimit(Double above, Double below, boolean enabled) {
this.above = above; this.above = above;
this.below = below; this.below = below;
this.enabled = enabled;
} }
public YDifferenceLimit(YDifferenceLimit yDifferenceLimit) { public YDifferenceLimit(YDifferenceLimit yDifferenceLimit) {
this.above = yDifferenceLimit.above; this.above = yDifferenceLimit.above;
this.below = yDifferenceLimit.below; this.below = yDifferenceLimit.below;
this.enabled = yDifferenceLimit.enabled;
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
} }
public Double getAbove() { public Double getAbove() {

View file

@ -106,6 +106,11 @@ public class Logic {
* check if the Y-level of the block is within the limits of the player, bounds are set in the {@link ServerConfig} * check if the Y-level of the block is within the limits of the player, bounds are set in the {@link ServerConfig}
*/ */
public static boolean checkYLimits(ServerPlayerEntity player, BlockPos blockPos) { public static boolean checkYLimits(ServerPlayerEntity player, BlockPos blockPos) {
ServerConfig.YDifferenceLimit yDifferenceLimit = FileData.getServerConfig().getYDifferenceLimit();
// check if enabled
if (!yDifferenceLimit.isEnabled()) return true;
double playerY = player.getBlockY(); double playerY = player.getBlockY();
double blockY = blockPos.getY(); double blockY = blockPos.getY();
// if the block is above the eye height // if the block is above the eye height
@ -116,9 +121,6 @@ public class Logic {
// get the height difference (positive) // get the height difference (positive)
double heightDifference = Math.abs(playerY - blockY); double heightDifference = Math.abs(playerY - blockY);
// get the config limits
ServerConfig.YDifferenceLimit yDifferenceLimit = FileData.getServerConfig().getYDifferenceLimit();
return (isAbove? yDifferenceLimit.getAbove() : yDifferenceLimit.getBelow()) >= heightDifference; return (isAbove? yDifferenceLimit.getAbove() : yDifferenceLimit.getBelow()) >= heightDifference;
} }

View file

@ -9,8 +9,8 @@
"Virt" "Virt"
], ],
"contact": { "contact": {
"homepage": "https://modrinth.com/mod/sit!", "homepage": "https://copeberg.org/virt/Sit",
"sources": "https://github.com/Oth3r/Sit" "sources": "https://copeberg.org/virt/Sit"
}, },
"license": "LGPL-3.0-only", "license": "LGPL-3.0-only",
"icon": "assets/sit-oth3r/icon.png", "icon": "assets/sit-oth3r/icon.png",
@ -38,4 +38,4 @@
"mixins": [ "mixins": [
"sit!.mixins.json" "sit!.mixins.json"
] ]
} }