mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
new y sitting limiter - #16
This commit is contained in:
parent
b46e10e835
commit
04d246a5bf
2 changed files with 90 additions and 6 deletions
|
@ -16,25 +16,33 @@ import java.nio.file.Files;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ServerConfig implements CustomFile<ServerConfig> {
|
||||
|
||||
@SerializedName("version")
|
||||
private Double version = 2.1;
|
||||
private Double version = 2.2;
|
||||
|
||||
@SerializedName("lang")
|
||||
private String lang = "en_us";
|
||||
@SerializedName("lang-options")
|
||||
private final String langOptions = "en_us, it_it, pt_br, tr_tr, zh_tw";
|
||||
|
||||
@SerializedName("keep-active")
|
||||
private Boolean keepActive = true;
|
||||
@SerializedName("sit-while-seated")
|
||||
private Boolean sitWhileSeated = false;
|
||||
@SerializedName("preset-blocks")
|
||||
private PresetBlocks presetBlocks = new PresetBlocks();
|
||||
|
||||
@SerializedName("sitting-eye-y-bounds")
|
||||
private YBounds yBounds = new YBounds();
|
||||
|
||||
@SerializedName("custom-enabled")
|
||||
private Boolean customEnabled = false;
|
||||
@SerializedName("custom-blocks")
|
||||
private ArrayList<SittingBlock> sittingBlocks = FileData.Defaults.SITTING_BLOCKS;
|
||||
|
||||
@SerializedName("blacklisted-blocks")
|
||||
private ArrayList<CustomBlock> blacklistedBlocks = FileData.Defaults.BLACKLISTED_BLOCKS;
|
||||
@SerializedName("interaction-blocks")
|
||||
|
@ -81,6 +89,10 @@ public class ServerConfig implements CustomFile<ServerConfig> {
|
|||
return presetBlocks;
|
||||
}
|
||||
|
||||
public YBounds getYBounds() {
|
||||
return yBounds;
|
||||
}
|
||||
|
||||
public Boolean isCustomEnabled() {
|
||||
return customEnabled;
|
||||
}
|
||||
|
@ -117,6 +129,13 @@ public class ServerConfig implements CustomFile<ServerConfig> {
|
|||
this.fullBlocks = fullBlocks;
|
||||
}
|
||||
|
||||
public PresetBlocks(PresetBlocks presetBlocks) {
|
||||
this.stairs = presetBlocks.stairs;
|
||||
this.slabs = presetBlocks.slabs;
|
||||
this.carpets = presetBlocks.carpets;
|
||||
this.fullBlocks = presetBlocks.fullBlocks;
|
||||
}
|
||||
|
||||
public boolean isStairs() {
|
||||
return stairs;
|
||||
}
|
||||
|
@ -134,6 +153,42 @@ public class ServerConfig implements CustomFile<ServerConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
public static class YBounds {
|
||||
@SerializedName("above")
|
||||
private Double above = 0.1;
|
||||
@SerializedName("below")
|
||||
private Double below = 3.0;
|
||||
|
||||
public YBounds() {
|
||||
}
|
||||
|
||||
public YBounds(Double above, Double below) {
|
||||
this.above = above;
|
||||
this.below = below;
|
||||
}
|
||||
|
||||
public YBounds(YBounds yBounds) {
|
||||
this.above = yBounds.above;
|
||||
this.below = yBounds.below;
|
||||
}
|
||||
|
||||
public Double getAbove() {
|
||||
return above;
|
||||
}
|
||||
|
||||
public void setAbove(Double above) {
|
||||
this.above = above;
|
||||
}
|
||||
|
||||
public Double getBelow() {
|
||||
return below;
|
||||
}
|
||||
|
||||
public void setBelow(Double below) {
|
||||
this.below = below;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
loadFileData(new ServerConfig());
|
||||
|
@ -150,17 +205,23 @@ public class ServerConfig implements CustomFile<ServerConfig> {
|
|||
this.lang = newFile.lang;
|
||||
this.keepActive = newFile.keepActive;
|
||||
this.sitWhileSeated = newFile.sitWhileSeated;
|
||||
this.presetBlocks = newFile.presetBlocks;
|
||||
|
||||
this.presetBlocks = new PresetBlocks(newFile.presetBlocks);
|
||||
|
||||
this.yBounds = new YBounds(newFile.yBounds);
|
||||
|
||||
this.customEnabled = newFile.customEnabled;
|
||||
this.sittingBlocks = newFile.sittingBlocks;
|
||||
this.blacklistedBlocks = newFile.blacklistedBlocks;
|
||||
this.sittingBlocks = newFile.sittingBlocks.stream().map(SittingBlock::new).collect(Collectors.toCollection(ArrayList::new));
|
||||
this.blacklistedBlocks = newFile.blacklistedBlocks.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new));
|
||||
this.interactionBlocks = newFile.interactionBlocks.stream().map(CustomBlock::new).collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
/// update to 2.1, just a new list, nothing to change
|
||||
if (version == 2.0) {
|
||||
version = 2.1;
|
||||
/// update to 2.2, new settings, no changes
|
||||
if (version >= 2.0 && version <= 2.1) {
|
||||
version = 2.2;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.util.Hand;
|
|||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.file.ServerConfig;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.file.HandSetting;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -27,6 +28,9 @@ public class Logic {
|
|||
if (!checkHands(player)) return false;
|
||||
}
|
||||
|
||||
// check if the block is in the right y level limits from the config
|
||||
if (!checkYLimits(player, blockPos)) return false;
|
||||
|
||||
ServerWorld serverWorld = player.getServerWorld();
|
||||
BlockState blockState = serverWorld.getBlockState(blockPos);
|
||||
|
||||
|
@ -74,6 +78,25 @@ public class Logic {
|
|||
return canSit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
double playerEyeY = player.getEyeY();
|
||||
double blockY = blockPos.getY();
|
||||
// if the block is above the eye height
|
||||
boolean isAbove = playerEyeY < blockY;
|
||||
// get the height difference (positive)
|
||||
double heightDifference = Math.abs(playerEyeY - blockY);
|
||||
// get the config limits
|
||||
ServerConfig.YBounds yBounds = FileData.getServerConfig().getYBounds();
|
||||
|
||||
// debug
|
||||
Data.LOGGER.info("{} {} can sit? {}", heightDifference, isAbove ? "Above" : "Below", (isAbove? yBounds.getAbove(): yBounds.getBelow()) >= heightDifference);
|
||||
|
||||
return (isAbove? yBounds.getAbove(): yBounds.getBelow()) >= heightDifference;
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the entity bound to the player from the game, using the player
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue