forked from virt-mirrors/Sit
allow disabling of y limit (default disabled lol)
This commit is contained in:
parent
2f18f285ca
commit
042b089712
3 changed files with 21 additions and 7 deletions
|
@ -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() {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue