Merge branch '1.20.6' into 1.20.4

# Conflicts:
#	gradle.properties
This commit is contained in:
Oth3r 2025-02-23 15:40:18 -06:00
commit 7658dbd40e
11 changed files with 307 additions and 87 deletions

View file

@ -28,6 +28,12 @@ public class CustomBlock {
this.blockStates = blockStates;
}
public CustomBlock(CustomBlock customBlock) {
this.blockIds = new ArrayList<>(customBlock.blockIds);
this.blockTags = new ArrayList<>(customBlock.blockTags);
this.blockStates = new ArrayList<>(customBlock.blockStates);
}
public ArrayList<String> getBlockIds() {
return blockIds;
}

View file

@ -89,9 +89,12 @@ public class FileData {
));
public static final ArrayList<CustomBlock> INTERACTION_BLOCKS = new ArrayList<>(Arrays.asList(
new CustomBlock(new ArrayList<>(Arrays.asList("minecraft:crafter")),new ArrayList<>(Arrays.asList(
new CustomBlock(new ArrayList<>(Arrays.asList(
"minecraft:crafter","minecraft:repeating_command_block","minecraft:chain_command_block","minecraft:command_block")),
new ArrayList<>(Arrays.asList(
"#minecraft:shulker_boxes","#c:player_workstations/furnaces","#c:player_workstations/crafting_tables",
"#c:villager_job_sites","#minecraft:trapdoors","#c:chests")),new ArrayList<>())
"#c:villager_job_sites","#minecraft:trapdoors","#c:chests")),
new ArrayList<>())
));
public static final HandSetting MAIN_HAND = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter(

View file

@ -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";
private final String langOptions = "en_us, it_it, pt_br, tr_tr, zh_tw, zh_ch, de_de";
@SerializedName("keep-active")
private Boolean keepActive = true;
@SerializedName("sit-while-seated")
private Boolean sitWhileSeated = false;
@SerializedName("preset-blocks")
private PresetBlocks presetBlocks = new PresetBlocks();
@SerializedName("height-difference-limit")
private YDifferenceLimit yDifferenceLimit = new YDifferenceLimit();
@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")
@ -43,15 +51,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
public ServerConfig() {}
public ServerConfig(ServerConfig serverConfig) {
this.version = serverConfig.version;
this.lang = serverConfig.lang;
this.keepActive = serverConfig.keepActive;
this.sitWhileSeated = serverConfig.sitWhileSeated;
this.presetBlocks = serverConfig.presetBlocks;
this.customEnabled = serverConfig.customEnabled;
this.sittingBlocks = serverConfig.sittingBlocks;
this.blacklistedBlocks = serverConfig.blacklistedBlocks;
this.interactionBlocks = serverConfig.interactionBlocks;
loadFileData(serverConfig);
}
public ServerConfig(Double version, String lang, boolean keepActive, boolean sitWhileSeated,
@ -89,6 +89,10 @@ public class ServerConfig implements CustomFile<ServerConfig> {
return presetBlocks;
}
public YDifferenceLimit getYDifferenceLimit() {
return yDifferenceLimit;
}
public Boolean isCustomEnabled() {
return customEnabled;
}
@ -125,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;
}
@ -142,6 +153,42 @@ public class ServerConfig implements CustomFile<ServerConfig> {
}
}
public static class YDifferenceLimit {
@SerializedName("above")
private Double above = 1.0;
@SerializedName("below")
private Double below = 1.0;
public YDifferenceLimit() {
}
public YDifferenceLimit(Double above, Double below) {
this.above = above;
this.below = below;
}
public YDifferenceLimit(YDifferenceLimit yDifferenceLimit) {
this.above = yDifferenceLimit.above;
this.below = yDifferenceLimit.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());
@ -158,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.yDifferenceLimit = new YDifferenceLimit(newFile.yDifferenceLimit);
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;
}
}

View file

@ -22,4 +22,9 @@ public class SittingBlock extends CustomBlock {
super(blockIds, blockTags, blockStates);
this.sittingHeight = sittingHeight;
}
public SittingBlock(SittingBlock sittingBlock) {
super(sittingBlock);
this.sittingHeight = sittingBlock.sittingHeight;
}
}

View file

@ -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,26 @@ 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 playerY = player.getBlockY();
double blockY = blockPos.getY();
// if the block is above the eye height
boolean isAbove = playerY < blockY;
// return true if equal
if (playerY == blockY) return true;
// get the height difference (positive)
double heightDifference = Math.abs(playerY - blockY);
// get the config limits
ServerConfig.YDifferenceLimit yDifferenceLimit = FileData.getServerConfig().getYDifferenceLimit();
return (isAbove? yDifferenceLimit.getAbove() : yDifferenceLimit.getBelow()) >= heightDifference;
}
/**
* removes the entity bound to the player from the game, using the player
*/
@ -170,11 +194,11 @@ public class Logic {
// get the message settings
String messageKey = "sit!.chat.sit_toggle."+(config.getEnabled()?"on":"off");
String messageKey = "sit!.chat.toggle_sit."+(config.getEnabled()?"on":"off");
Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED;
// send the player the actionbar message
return Utl.lang("sit!.chat.sit_toggle",
return Utl.lang("sit!.chat.toggle_sit",
Utl.lang(messageKey).formatted(messageColor));
} else {
// unsupported server message if not in a Sit! server

View file

@ -204,6 +204,10 @@ public class Utl {
}
public static class Entity {
/**
* the customizable y height of the entity, as some versions have different sitting heights on the entity
*/
private static final double Y_ADJUSTMENT = 0;
/**
* checks if the entity's block is still there, & is valid
@ -220,8 +224,12 @@ public class Utl {
* gets the bound block pos of the sit entity
*/
public static BlockPos getBlockPos(DisplayEntity.TextDisplayEntity entity) {
// the entity Y level, adjusted
// the adjustment - is the opposite of the offset applied in Entity.create()
double entityY = entity.getY() + (Y_ADJUSTMENT*-1);
// get the block pos
BlockPos pos = new BlockPos(entity.getBlockX(),entity.getBlockY(),entity.getBlockZ());
BlockPos pos = new BlockPos(entity.getBlockX(),(int)entityY,entity.getBlockZ());
// if above the block, subtract 1
if (isAboveBlockHeight(entity)) {
pos = pos.add(0,-1,0);
@ -253,20 +261,20 @@ public class Utl {
entity.setInvulnerable(true);
entity.setInvisible(true);
/// make a double for adjusting the entity height if some versions change the player sit height on entities again
double adjustmentY = 0;
// get the entities y level
double entityY = blockPos.getY();
entityY += sitHeight + adjustmentY;
entityY += sitHeight;
// set the entities position
entity.updatePositionAndAngles(blockPos.getX()+.5, entityY, blockPos.getZ()+.5, 0, 0);
entity.updatePosition(blockPos.getX()+.5, entityY, blockPos.getZ()+.5);
// change pitch based on if player is sitting below block height or not (full block height only)
if (entity.getY() == blockPos.getY() + 1) entity.setPitch(90); // below
else entity.setPitch(-90); // above
// adjusting the entity height after doing the main calculations, for correct player visuals
entity.updatePosition(entity.getX(),entityY+Y_ADJUSTMENT,entity.getZ());
return entity;
}