mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
Merge branch 'master' into snapshot
# Conflicts: # gradle.properties # src/main/java/one/oth3r/sit/ModMenu.java # src/main/java/one/oth3r/sit/Sit.java # src/main/java/one/oth3r/sit/SitClient.java
This commit is contained in:
commit
c6fb594d1f
8 changed files with 184 additions and 112 deletions
11
README.md
11
README.md
|
@ -7,17 +7,23 @@
|
|||
Sit on **stairs**, **slabs**, **carpets** by default, and sit on everything else using the config!
|
||||
You can also customize hand restrictions to stop accidentally sitting down!
|
||||
The mod also has full Geyser support! Enjoy sitting with everyone, weather they are on Bedrock or Java!
|
||||
|
||||
### Where to install?
|
||||
**Sit!** works on the server (singleplayer included), with support for clients that join in to use their own settings to sit.
|
||||
**Sit!** works on the server (singleplayer included), also with support for clients that join in to use their own settings to sit.
|
||||
|
||||
## Help localize Sit! on [Crowdin](https://crowdin.com/project/oth3r-sit)!
|
||||

|
||||
|
||||
## Check out my other Projects!
|
||||
[](https://modrinth.com/mod/caligo)
|
||||
[](https://modrinth.com/mod/directionhud)
|
||||
[](https://modrinth.com/plugin/directionhud-plugin)
|
||||
|
||||
# Features
|
||||
|
||||
### Hand Restrictions
|
||||
Don't want to accidentally sit down? Set custom restrictions for each hand in the config!
|
||||
|
||||
* Per player hand restrictions when connecting to a `Sit!` server on a `Sit!` Client!
|
||||
|
||||

|
||||
|
@ -26,6 +32,7 @@ Don't want to accidentally sit down? Set custom restrictions for each hand in th
|
|||
Want to sit on _**EVERY**_ block? With the config you can add more options to sit on! Custom block states are also supported.
|
||||
|
||||

|
||||
|
||||
### Customizable Config
|
||||
Configure to your hearts desire with the in-game config with **[ModMenu](https://modrinth.com/mod/modmenu)** & **[YetAnotherConfigLib](https://modrinth.com/mod/yacl)**, or use the provided config file for servers!
|
||||
|
||||
|
@ -35,3 +42,5 @@ Configure to your hearts desire with the in-game config with **[ModMenu](https:/
|
|||
## Future Goals
|
||||
* Forge Port (probably NeoForge 1.21)
|
||||
* Custom dismounting logic
|
||||
* better config (coming soon!)
|
||||
* keybindings (next update)
|
||||
|
|
|
@ -9,7 +9,7 @@ yarn_mappings=24w03b+build.6
|
|||
loader_version=0.15.6
|
||||
|
||||
# Mod Properties
|
||||
mod_version=s1.1.3+24w03b
|
||||
mod_version=s1.1.4+24w03b
|
||||
maven_group=one.oth3r
|
||||
archives_base_name=sit!
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import one.oth3r.sit.Utl.HandType;
|
||||
import one.oth3r.sit.Utl.HandSettings.HandType;
|
||||
import one.oth3r.sit.file.Config;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -38,25 +39,25 @@ public class Events {
|
|||
ArrayList<UseAction> notUsable = new ArrayList<>(food);
|
||||
notUsable.add(UseAction.NONE);
|
||||
HashMap<HandType, ItemStack> itemMap = new HashMap<>();
|
||||
itemMap.put(HandType.main,player.getMainHandStack());
|
||||
itemMap.put(HandType.off,player.getOffHandStack());
|
||||
itemMap.put(Utl.HandSettings.HandType.main,player.getMainHandStack());
|
||||
itemMap.put(Utl.HandSettings.HandType.off,player.getOffHandStack());
|
||||
// if sneaking cant sit
|
||||
if (player.isSneaking()) return false;
|
||||
// for both hands
|
||||
for (HandType type:HandType.values()) {
|
||||
for (HandType type: Utl.HandSettings.HandType.values()) {
|
||||
ItemStack targetStack = itemMap.get(type);
|
||||
// if req is empty and the item isn't empty, false
|
||||
if (Utl.getReq(player,type).equals(config.HandRequirement.empty) && !targetStack.isEmpty()) return false;
|
||||
if (Utl.HandSettings.getReq(player,type).equals(Config.HandRequirement.empty) && !targetStack.isEmpty()) return false;
|
||||
// if req is restrictive
|
||||
if (Utl.getReq(player,type).equals(config.HandRequirement.restrictive)) {
|
||||
if (Utl.HandSettings.getReq(player,type).equals(Config.HandRequirement.restrictive)) {
|
||||
// if item is in blacklist, false
|
||||
if (checkList(Utl.getList(player,type,"blacklist"),targetStack)) return false;
|
||||
if (checkList(Utl.HandSettings.getList(player,type,"blacklist"),targetStack)) return false;
|
||||
// if item is NOT in whitelist
|
||||
if (!checkList(Utl.getList(player,type,"whitelist"),targetStack)) {
|
||||
if (!checkList(Utl.HandSettings.getList(player,type,"whitelist"),targetStack)) {
|
||||
// if block is restricted and items is block, false, ect
|
||||
if (Utl.getBool(player,type,"block") && (targetStack.getItem() instanceof BlockItem)) return false;
|
||||
if (Utl.getBool(player,type,"food") && food.contains(targetStack.getUseAction())) return false;
|
||||
if (Utl.getBool(player,type,"usable") && !notUsable.contains(targetStack.getUseAction())) return false;
|
||||
if (Utl.HandSettings.getBool(player,type,"block") && (targetStack.getItem() instanceof BlockItem)) return false;
|
||||
if (Utl.HandSettings.getBool(player,type,"food") && food.contains(targetStack.getUseAction())) return false;
|
||||
if (Utl.HandSettings.getBool(player,type,"usable") && !notUsable.contains(targetStack.getUseAction())) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +73,7 @@ public class Events {
|
|||
// get a hashmap of custom blocks
|
||||
HashMap<String,HashMap<String,Object>> map = new HashMap<>();
|
||||
int i = 1;
|
||||
for (String s:config.customBlocks) {
|
||||
for (String s: Config.customBlocks) {
|
||||
String[] split = s.split("\\|");
|
||||
HashMap<String,Object> data = new HashMap<>();
|
||||
data.put("block",split[0]);
|
||||
|
@ -100,12 +101,12 @@ public class Events {
|
|||
for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false;
|
||||
|
||||
// return for the 4 default types
|
||||
if (block instanceof StairsBlock && config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM;
|
||||
if (block instanceof SlabBlock && config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM;
|
||||
if (block instanceof CarpetBlock && config.carpetsOn) return true;
|
||||
if (blockState.isFullCube(world,pos.add(0,1,0)) && config.fullBlocksOn) return true;
|
||||
if (block instanceof StairsBlock && Config.stairsOn) return blockState.get(StairsBlock.HALF) == BlockHalf.BOTTOM;
|
||||
if (block instanceof SlabBlock && Config.slabsOn) return blockState.get(SlabBlock.TYPE) == SlabType.BOTTOM;
|
||||
if (block instanceof CarpetBlock && Config.carpetsOn) return true;
|
||||
if (blockState.isFullCube(world,pos.add(0,1,0)) && Config.fullBlocksOn) return true;
|
||||
// custom checker
|
||||
if (config.customOn && config.customBlocks.size() != 0) {
|
||||
if (Config.customOn && Config.customBlocks.size() != 0) {
|
||||
for (HashMap<String,Object> map:getCustomBlocks().values()) {
|
||||
String blockID = Registries.BLOCK.getId(block).toString();
|
||||
if (map.get("block").equals(blockID)) {
|
||||
|
@ -149,7 +150,7 @@ public class Events {
|
|||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0);
|
||||
hitBoxY = 2;
|
||||
}
|
||||
if (config.customOn && config.customBlocks.size() != 0) {
|
||||
if (Config.customOn && !Config.customBlocks.isEmpty()) {
|
||||
for (HashMap<String,Object> map:getCustomBlocks().values()) {
|
||||
String blockID = Registries.BLOCK.getId(block).toString();
|
||||
if (map.get("block").equals(blockID)) {
|
||||
|
@ -167,6 +168,24 @@ public class Events {
|
|||
if (entity.getY() <= pos.getY()+.35+oneTwentyTwo) entity.setPitch(90); // below
|
||||
else entity.setPitch(-90); // above
|
||||
}
|
||||
public static boolean sit(ServerPlayerEntity player, BlockPos pos) {
|
||||
// todo interactions entity to make the sitting hitbox?
|
||||
World world = player.getWorld();
|
||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||
setEntity(pos,world,entity);
|
||||
if (checkBlocks(pos,world,isAboveBlockheight(entity))) {
|
||||
if (entities.containsKey(player)) {
|
||||
if (!Config.sitWhileSeated) return false;
|
||||
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
entities.remove(player);
|
||||
}
|
||||
player.getServerWorld().spawnEntity(entity);
|
||||
player.startRiding(entity);
|
||||
entities.put(player,entity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static void register() {
|
||||
ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp));
|
||||
// PLAYER JOIN
|
||||
|
@ -174,12 +193,12 @@ public class Events {
|
|||
ServerPlayerEntity player = handler.player;
|
||||
checkPlayers.put(player,2);
|
||||
// put server settings in the player settings
|
||||
Sit.playerSettings.put(player,Utl.getHandSettings());
|
||||
Sit.playerSettings.put(player, Utl.HandSettings.getHandSettings());
|
||||
});
|
||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
||||
ServerPlayerEntity player = handler.player;
|
||||
if (entities.containsKey(player)) {
|
||||
if (!config.keepActive) {
|
||||
if (!Config.keepActive) {
|
||||
player.dismountVehicle();
|
||||
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
}
|
||||
|
@ -196,22 +215,12 @@ public class Events {
|
|||
if (player == null) return ActionResult.PASS;
|
||||
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
// check the players hands
|
||||
if (!checkLogic(player)) return ActionResult.PASS;
|
||||
// todo interactions entity to make the hitbox?
|
||||
// make the entity first before checking to make sure the blocks around are fine
|
||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||
setEntity(pos,world,entity);
|
||||
if (checkBlocks(pos,world,isAboveBlockheight(entity))) {
|
||||
if (entities.containsKey(player)) {
|
||||
if (!config.sitWhileSeated) return ActionResult.PASS;
|
||||
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
entities.remove(player);
|
||||
}
|
||||
player.getServerWorld().spawnEntity(entity);
|
||||
player.startRiding(entity);
|
||||
entities.put(player,entity);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
// make the player sit
|
||||
boolean status = sit(player,pos);
|
||||
// if sat, cancel / FAIL the use block event
|
||||
if (status) return ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.reflect.TypeToken;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import one.oth3r.sit.file.Config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -77,10 +78,10 @@ public class LangReader {
|
|||
public static void loadLanguageFile() {
|
||||
try {
|
||||
ClassLoader classLoader = Sit.class.getClassLoader();
|
||||
InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ config.lang+".json");
|
||||
InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ Config.lang+".json");
|
||||
if (inputStream == null) {
|
||||
inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+config.defaults.lang+".json");
|
||||
config.lang = config.defaults.lang;
|
||||
inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ Config.defaults.lang+".json");
|
||||
Config.lang = Config.defaults.lang;
|
||||
}
|
||||
if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. DIRECTIONHUD WILL BREAK.");
|
||||
Type type = new TypeToken<Map<String, String>>(){}.getType();
|
||||
|
|
|
@ -16,7 +16,7 @@ import net.minecraft.server.command.CommandManager;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import one.oth3r.sit.file.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class Sit implements ModInitializer {
|
|||
//todo future:
|
||||
// make it so it updates the sitting height and pos based on the block so if it changed while offline it still works (or if stair changes shape)
|
||||
// inner stair offset & custom support for that ig
|
||||
config.load();
|
||||
Config.load();
|
||||
Events.register();
|
||||
//PACKETS
|
||||
PayloadTypeRegistry.playC2S().register(SettingsPayload.ID, SettingsPayload.CODEC);
|
||||
|
|
|
@ -7,15 +7,13 @@ import com.mojang.brigadier.context.CommandContext;
|
|||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.TextColor;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import one.oth3r.sit.file.Config;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
@ -48,31 +46,24 @@ public class SitCommand {
|
|||
// if console
|
||||
if (player == null) {
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
config.load();
|
||||
Config.load();
|
||||
Sit.LOGGER.info(Sit.lang("key.sit.command.reloaded").getString());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("sit")) {
|
||||
BlockPos pos = player.getBlockPos();
|
||||
if (!(player.getY() -((int) player.getY()) > 0.00)) {
|
||||
// get the block under the player if player on top of a solid
|
||||
if (!(player.getY() - ((int) player.getY()) > 0.00)) {
|
||||
pos = pos.add(0,-1,0);
|
||||
}
|
||||
World world = player.getWorld();
|
||||
// if already sitting, ignore
|
||||
if (Events.entities.containsKey(player)) return 1;
|
||||
// make entity first to check the blocks
|
||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||
Events.setEntity(pos,world,entity);
|
||||
if (Events.checkBlocks(pos,world,Events.isAboveBlockheight(entity))) {
|
||||
player.getServerWorld().spawnEntity(entity);
|
||||
player.startRiding(entity);
|
||||
Events.entities.put(player,entity);
|
||||
return 1;
|
||||
}
|
||||
// sit
|
||||
Events.sit(player,pos);
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
config.load();
|
||||
Config.load();
|
||||
player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("purgeChairEntities")) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import one.oth3r.sit.file.Config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
@ -11,35 +12,59 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
|
||||
public class Utl {
|
||||
enum HandType {
|
||||
main,
|
||||
off
|
||||
public static class HandSettings {
|
||||
public static HashMap<String,String> getHandSettings() {
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
HashMap<String,String> settings = new HashMap<>();
|
||||
settings.put("hand.main.requirement",String.valueOf(Config.mainReq));
|
||||
settings.put("hand.main.block",String.valueOf(Config.mainBlock));
|
||||
settings.put("hand.main.food",String.valueOf(Config.mainFood));
|
||||
settings.put("hand.main.usable",String.valueOf(Config.mainUsable));
|
||||
settings.put("hand.main.whitelist",gson.toJson(Config.mainWhitelist));
|
||||
settings.put("hand.main.blacklist",gson.toJson(Config.mainBlacklist));
|
||||
settings.put("hand.off.requirement",String.valueOf(Config.offReq));
|
||||
settings.put("hand.off.block",String.valueOf(Config.offBlock));
|
||||
settings.put("hand.off.food",String.valueOf(Config.offFood));
|
||||
settings.put("hand.off.usable",String.valueOf(Config.offUsable));
|
||||
settings.put("hand.off.whitelist",gson.toJson(Config.offWhitelist));
|
||||
settings.put("hand.off.blacklist",gson.toJson(Config.offBlacklist));
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static Config.HandRequirement getReq(ServerPlayerEntity player, HandType type) {
|
||||
return Config.HandRequirement.get(Sit.playerSettings.get(player).get("hand."+type+".requirement"));
|
||||
}
|
||||
|
||||
public static List<String> getList(ServerPlayerEntity player, HandType type, String setting) {
|
||||
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
|
||||
return new Gson().fromJson(Sit.playerSettings.get(player).get("hand."+type+"."+setting),listType);
|
||||
}
|
||||
|
||||
public static boolean getBool(ServerPlayerEntity player, HandType type, String setting) {
|
||||
return Boolean.parseBoolean(Sit.playerSettings.get(player).get("hand."+type+"."+setting));
|
||||
}
|
||||
|
||||
public enum HandType {
|
||||
main,
|
||||
off
|
||||
}
|
||||
}
|
||||
public static HashMap<String,String> getHandSettings() {
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
HashMap<String,String> settings = new HashMap<>();
|
||||
settings.put("hand.main.requirement",String.valueOf(config.mainReq));
|
||||
settings.put("hand.main.block",String.valueOf(config.mainBlock));
|
||||
settings.put("hand.main.food",String.valueOf(config.mainFood));
|
||||
settings.put("hand.main.usable",String.valueOf(config.mainUsable));
|
||||
settings.put("hand.main.whitelist",gson.toJson(config.mainWhitelist));
|
||||
settings.put("hand.main.blacklist",gson.toJson(config.mainBlacklist));
|
||||
settings.put("hand.off.requirement",String.valueOf(config.offReq));
|
||||
settings.put("hand.off.block",String.valueOf(config.offBlock));
|
||||
settings.put("hand.off.food",String.valueOf(config.offFood));
|
||||
settings.put("hand.off.usable",String.valueOf(config.offUsable));
|
||||
settings.put("hand.off.whitelist",gson.toJson(config.offWhitelist));
|
||||
settings.put("hand.off.blacklist",gson.toJson(config.offBlacklist));
|
||||
return settings;
|
||||
}
|
||||
public static config.HandRequirement getReq(ServerPlayerEntity player, HandType type) {
|
||||
return config.HandRequirement.get(Sit.playerSettings.get(player).get("hand."+type+".requirement"));
|
||||
}
|
||||
public static List<String> getList(ServerPlayerEntity player, HandType type, String setting) {
|
||||
Type listType = new TypeToken<ArrayList<String>>() {}.getType();
|
||||
return new Gson().fromJson(Sit.playerSettings.get(player).get("hand."+type+"."+setting),listType);
|
||||
}
|
||||
public static boolean getBool(ServerPlayerEntity player, HandType type, String setting) {
|
||||
return Boolean.parseBoolean(Sit.playerSettings.get(player).get("hand."+type+"."+setting));
|
||||
public static class Num {
|
||||
public static boolean isInt(String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean isFloat(String string) {
|
||||
try {
|
||||
Float.parseFloat(string);
|
||||
} catch (NumberFormatException nfe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package one.oth3r.sit;
|
||||
package one.oth3r.sit.file;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import one.oth3r.sit.LangReader;
|
||||
import one.oth3r.sit.Sit;
|
||||
import one.oth3r.sit.SitClient;
|
||||
import one.oth3r.sit.Utl.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -14,7 +19,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class config {
|
||||
public class Config {
|
||||
public static String lang = defaults.lang;
|
||||
public static boolean keepActive = defaults.keepActive;
|
||||
public static boolean sitWhileSeated = defaults.sitWhileSeated;
|
||||
|
@ -24,7 +29,7 @@ public class config {
|
|||
public static boolean fullBlocksOn = defaults.fullBlocksOn;
|
||||
public static boolean customOn = defaults.customOn;
|
||||
public static List<String> customBlocks = defaults.customBlocks;
|
||||
enum HandRequirement {
|
||||
public enum HandRequirement {
|
||||
empty,
|
||||
restrictive,
|
||||
none;
|
||||
|
@ -62,17 +67,35 @@ public class config {
|
|||
Properties properties = new Properties();
|
||||
properties.load(fileStream);
|
||||
String ver = (String) properties.computeIfAbsent("version", a -> String.valueOf(defaults.version));
|
||||
// if the old version system (v1.0) remove "v:
|
||||
|
||||
// if the old version system (v1.0) remove "v"
|
||||
if (ver.contains("v")) ver = ver.substring(1);
|
||||
|
||||
loadVersion(properties,Double.parseDouble(ver));
|
||||
LangReader.loadLanguageFile();
|
||||
|
||||
save();
|
||||
} catch (Exception f) {
|
||||
} catch (Exception e) {
|
||||
//read fail
|
||||
f.printStackTrace();
|
||||
e.printStackTrace();
|
||||
save();
|
||||
}
|
||||
}
|
||||
public static ArrayList<String> validateCustomBlocks(ArrayList<String> fix) {
|
||||
ArrayList<String> out = new ArrayList<>();
|
||||
for (String entry : fix) {
|
||||
String[] split = entry.split("\\|");
|
||||
// skip if not the right size
|
||||
if (split.length < 3 || split.length > 4) continue;
|
||||
// keep going if that block exists
|
||||
// if (Registries.BLOCK.stream().anyMatch(match -> Registries.BLOCK.getId(match).toString().equals(split[0]))) {}
|
||||
// if the other entries aren't correct, skip
|
||||
if (!Num.isFloat(split[1]) || !Num.isInt(split[2])) continue;
|
||||
// add if everything is a okay
|
||||
out.add(entry);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
public static void loadVersion(Properties properties, double version) {
|
||||
try {
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
@ -86,17 +109,23 @@ public class config {
|
|||
carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> String.valueOf(defaults.carpetsOn)));
|
||||
fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> String.valueOf(defaults.fullBlocksOn)));
|
||||
customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> String.valueOf(defaults.customOn)));
|
||||
customBlocks = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType);
|
||||
mainReq = HandRequirement.valueOf((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaults.mainReq)));
|
||||
try {
|
||||
customBlocks = validateCustomBlocks(new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("custom-blocks", a -> gson.toJson(defaults.customBlocks)), listType));
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
mainReq = HandRequirement.get((String) properties.computeIfAbsent("hand.main.requirement", a -> String.valueOf(defaults.mainReq)));
|
||||
mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.block", a -> String.valueOf(defaults.mainBlock)));
|
||||
mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.food", a -> String.valueOf(defaults.mainFood)));
|
||||
mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.main.usable", a -> String.valueOf(defaults.mainUsable)));
|
||||
mainWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("hand.main.whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType);
|
||||
mainBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("hand.main.blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType);
|
||||
offReq = HandRequirement.valueOf((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaults.offReq)));
|
||||
try {
|
||||
mainWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("hand.main.whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType);
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
try {
|
||||
mainBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("hand.main.blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType);
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
offReq = HandRequirement.get((String) properties.computeIfAbsent("hand.off.requirement", a -> String.valueOf(defaults.offReq)));
|
||||
offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.block", a -> String.valueOf(defaults.offBlock)));
|
||||
offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.food", a -> String.valueOf(defaults.offFood)));
|
||||
offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("hand.off.usable", a -> String.valueOf(defaults.offUsable)));
|
||||
|
@ -105,22 +134,30 @@ public class config {
|
|||
offBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("hand.off.blacklist", a -> gson.toJson(defaults.offBlacklist)), listType);
|
||||
if (version == 1.0) {
|
||||
mainReq = HandRequirement.valueOf((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaults.mainReq)));
|
||||
mainReq = HandRequirement.get((String) properties.computeIfAbsent("main-hand-requirement", a -> String.valueOf(defaults.mainReq)));
|
||||
mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> String.valueOf(defaults.mainBlock)));
|
||||
mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> String.valueOf(defaults.mainFood)));
|
||||
mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> String.valueOf(defaults.mainUsable)));
|
||||
mainWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("main-hand-whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType);
|
||||
mainBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("main-hand-blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType);
|
||||
offReq = HandRequirement.valueOf((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaults.offReq)));
|
||||
try {
|
||||
mainWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("main-hand-whitelist", a -> gson.toJson(defaults.mainWhitelist)), listType);
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
try {
|
||||
mainBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("main-hand-blacklist", a -> gson.toJson(defaults.mainBlacklist)), listType);
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
offReq = HandRequirement.get((String) properties.computeIfAbsent("off-hand-requirement", a -> String.valueOf(defaults.offReq)));
|
||||
offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> String.valueOf(defaults.offBlock)));
|
||||
offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> String.valueOf(defaults.offFood)));
|
||||
offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> String.valueOf(defaults.offUsable)));
|
||||
offWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("off-hand-whitelist", a -> gson.toJson(defaults.offWhitelist)), listType);
|
||||
offBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("off-hand-blacklist", a -> gson.toJson(defaults.offBlacklist)), listType);
|
||||
try {
|
||||
offWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("off-hand-whitelist", a -> gson.toJson(defaults.offWhitelist)), listType);
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
try {
|
||||
offBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("off-hand-blacklist", a -> gson.toJson(defaults.offBlacklist)), listType);
|
||||
} catch (JsonSyntaxException ignore) {}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Sit.LOGGER.info("ERROR LOADING CONFIG - PLEASE REPORT WITH THE ERROR LOG");
|
||||
|
@ -191,7 +228,7 @@ public class config {
|
|||
public static boolean carpetsOn = true;
|
||||
public static boolean fullBlocksOn = false;
|
||||
public static boolean customOn = false;
|
||||
public static List<String> customBlocks = List.of("minecraft:campfire|.46|1|lit=false","minecraft:soul_campfire|.46|1|lit=false");
|
||||
public static List<String> customBlocks = List.of("minecraft:campfire|.46|1|lit=false","minecraft:soul_campfire|.46|1|lit=false,waterlogged=false");
|
||||
public static HandRequirement mainReq = HandRequirement.empty;
|
||||
public static boolean mainBlock = false;
|
||||
public static boolean mainFood = false;
|
Loading…
Add table
Add a link
Reference in a new issue