customblock to sittingblock & customblock base without sitting height

This commit is contained in:
Oth3r 2024-09-20 22:24:17 -05:00
commit a2a944da2f
5 changed files with 42 additions and 23 deletions

View file

@ -17,16 +17,14 @@ public class CustomBlock {
private ArrayList<String> blockTags = new ArrayList<>(); private ArrayList<String> blockTags = new ArrayList<>();
@SerializedName("blockstates") @SerializedName("blockstates")
private ArrayList<String> blockStates = new ArrayList<>(); private ArrayList<String> blockStates = new ArrayList<>();
@SerializedName("sitting-height")
private Double sittingHeight = 0.5;
public CustomBlock() {} public CustomBlock() {}
public CustomBlock(ArrayList<String> blockIds, ArrayList<String> blockTags, ArrayList<String> blockStates, Double sittingHeight) { public CustomBlock(ArrayList<String> blockIds, ArrayList<String> blockTags, ArrayList<String> blockStates) {
this.blockIds = blockIds; this.blockIds = blockIds;
this.blockTags = blockTags; this.blockTags = blockTags;
this.blockStates = blockStates; this.blockStates = blockStates;
this.sittingHeight = sittingHeight;
} }
public ArrayList<String> getBlockIds() { public ArrayList<String> getBlockIds() {
@ -41,9 +39,7 @@ public class CustomBlock {
return blockStates; return blockStates;
} }
public Double getSittingHeight() {
return sittingHeight;
}
/** /**
* checks if the blockstate matches the CustomBlock params * checks if the blockstate matches the CustomBlock params

View file

@ -92,10 +92,10 @@ public class FileData {
} }
public static class Defaults { public static class Defaults {
public static final ArrayList<CustomBlock> CUSTOM_BLOCKS = new ArrayList<>(Arrays.asList( public static final ArrayList<SittingBlock> SITTING_BLOCKS = new ArrayList<>(Arrays.asList(
new CustomBlock(new ArrayList<>(),new ArrayList<>(Arrays.asList("#minecraft:campfires")), new ArrayList<>(Arrays.asList("lit=false")),.43), new SittingBlock(new ArrayList<>(),new ArrayList<>(Arrays.asList("#minecraft:campfires")), new ArrayList<>(Arrays.asList("lit=false")),.43),
new CustomBlock(new ArrayList<>(Arrays.asList("!minecraft:oak_log", "minecraft:crimson_stem")), new ArrayList<>(Arrays.asList("#minecraft:logs")), new ArrayList<>(Arrays.asList("!axis=y")),1.0), new SittingBlock(new ArrayList<>(Arrays.asList("!minecraft:oak_log", "minecraft:crimson_stem")), new ArrayList<>(Arrays.asList("#minecraft:logs")), new ArrayList<>(Arrays.asList("!axis=y")),1.0),
new CustomBlock(new ArrayList<>(Arrays.asList()), new ArrayList<>(Arrays.asList("#minecraft:beds")), new ArrayList<>(Arrays.asList("part=foot","occupied=false")),.5) new SittingBlock(new ArrayList<>(Arrays.asList()), new ArrayList<>(Arrays.asList("#minecraft:beds")), new ArrayList<>(Arrays.asList("part=foot","occupied=false")),.5)
)); ));
public static final HandSetting MAIN_HAND = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter( public static final HandSetting MAIN_HAND = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter(

View file

@ -34,9 +34,11 @@ public class ServerConfig implements CustomFile<ServerConfig> {
@SerializedName("custom-enabled") @SerializedName("custom-enabled")
private Boolean customEnabled = false; private Boolean customEnabled = false;
@SerializedName("custom-blocks") @SerializedName("custom-blocks")
private ArrayList<CustomBlock> customBlocks = FileData.Defaults.CUSTOM_BLOCKS; private ArrayList<SittingBlock> sittingBlocks = FileData.Defaults.SITTING_BLOCKS;
@SerializedName("blacklisted-blocks") @SerializedName("blacklisted-blocks")
private ArrayList<String> blacklistedBlocks = new ArrayList<>(); private ArrayList<String> blacklistedBlocks = new ArrayList<>();
@SerializedName("blacklisted-interactions")
private ArrayList<String> blacklistedInteractions = new ArrayList<>();
public ServerConfig() {} public ServerConfig() {}
@ -47,18 +49,18 @@ public class ServerConfig implements CustomFile<ServerConfig> {
this.sitWhileSeated = serverConfig.sitWhileSeated; this.sitWhileSeated = serverConfig.sitWhileSeated;
this.presetBlocks = serverConfig.presetBlocks; this.presetBlocks = serverConfig.presetBlocks;
this.customEnabled = serverConfig.customEnabled; this.customEnabled = serverConfig.customEnabled;
this.customBlocks = serverConfig.customBlocks; this.sittingBlocks = serverConfig.sittingBlocks;
this.blacklistedBlocks = serverConfig.blacklistedBlocks; this.blacklistedBlocks = serverConfig.blacklistedBlocks;
} }
public ServerConfig(Double version, String lang, boolean keepActive, boolean sitWhileSeated, PresetBlocks presetBlocks, boolean customEnabled, ArrayList<CustomBlock> customBlocks, ArrayList<String> blacklistedBlocks) { public ServerConfig(Double version, String lang, boolean keepActive, boolean sitWhileSeated, PresetBlocks presetBlocks, boolean customEnabled, ArrayList<SittingBlock> sittingBlocks, ArrayList<String> blacklistedBlocks) {
this.version = version; this.version = version;
this.lang = lang; this.lang = lang;
this.keepActive = keepActive; this.keepActive = keepActive;
this.sitWhileSeated = sitWhileSeated; this.sitWhileSeated = sitWhileSeated;
this.presetBlocks = presetBlocks; this.presetBlocks = presetBlocks;
this.customEnabled = customEnabled; this.customEnabled = customEnabled;
this.customBlocks = customBlocks; this.sittingBlocks = sittingBlocks;
this.blacklistedBlocks = blacklistedBlocks; this.blacklistedBlocks = blacklistedBlocks;
} }
@ -86,8 +88,8 @@ public class ServerConfig implements CustomFile<ServerConfig> {
return customEnabled; return customEnabled;
} }
public ArrayList<CustomBlock> getCustomBlocks() { public ArrayList<SittingBlock> getSittingBlocks() {
return customBlocks; return sittingBlocks;
} }
public ArrayList<String> getBlacklistedBlocks() { public ArrayList<String> getBlacklistedBlocks() {
@ -149,7 +151,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
this.sitWhileSeated = newFile.sitWhileSeated; this.sitWhileSeated = newFile.sitWhileSeated;
this.presetBlocks = newFile.presetBlocks; this.presetBlocks = newFile.presetBlocks;
this.customEnabled = newFile.customEnabled; this.customEnabled = newFile.customEnabled;
this.customBlocks = newFile.customBlocks; this.sittingBlocks = newFile.sittingBlocks;
this.blacklistedBlocks = newFile.blacklistedBlocks; this.blacklistedBlocks = newFile.blacklistedBlocks;
} }
@ -229,9 +231,9 @@ public class ServerConfig implements CustomFile<ServerConfig> {
/** /**
* gets a list of custom blocks from the legacy way of entering custom sit blocks * gets a list of custom blocks from the legacy way of entering custom sit blocks
*/ */
private static ArrayList<CustomBlock> getCustomBlocks(ArrayList<String> fix) { private static ArrayList<SittingBlock> getCustomBlocks(ArrayList<String> fix) {
//eg. minecraft:campfire|.46|1|lit=false //eg. minecraft:campfire|.46|1|lit=false
ArrayList<CustomBlock> out = new ArrayList<>(); ArrayList<SittingBlock> out = new ArrayList<>();
for (String entry : fix) { for (String entry : fix) {
String[] split = entry.split("\\|"); String[] split = entry.split("\\|");
// skip if not the right size // skip if not the right size
@ -247,7 +249,7 @@ public class ServerConfig implements CustomFile<ServerConfig> {
} }
// add if everything is A-OK // add if everything is A-OK
out.add(new CustomBlock( out.add(new SittingBlock(
new ArrayList<>(Arrays.asList(split[0])), new ArrayList<>(Arrays.asList(split[0])),
new ArrayList<>(),blockstates,Double.parseDouble(split[1]))); new ArrayList<>(),blockstates,Double.parseDouble(split[1])));
} }

View file

@ -0,0 +1,21 @@
package one.oth3r.sit.file;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
public class SittingBlock extends CustomBlock {
@SerializedName("sitting-height")
private Double sittingHeight = 0.5;
public Double getSittingHeight() {
return sittingHeight;
}
public SittingBlock() {}
public SittingBlock(ArrayList<String> blockIds, ArrayList<String> blockTags, ArrayList<String> blockStates, Double sittingHeight) {
super(blockIds, blockTags, blockStates);
this.sittingHeight = sittingHeight;
}
}

View file

@ -180,9 +180,9 @@ public class Utl {
// if the block is on the blacklist, false // if the block is on the blacklist, false
if (config.getBlacklistedBlocks().contains(getBlockID(blockState))) return null; if (config.getBlacklistedBlocks().contains(getBlockID(blockState))) return null;
for (CustomBlock customBlock : config.getCustomBlocks()) { for (SittingBlock dittingBlock : config.getSittingBlocks()) {
// if the block is valid, true // if the block is valid, true
if (customBlock.isValid(blockState)) return customBlock.getSittingHeight(); if (dittingBlock.isValid(blockState)) return dittingBlock.getSittingHeight();
} }
} }