forked from virt-mirrors/Sit
Initial commit
This commit is contained in:
commit
ff1c9342ca
17 changed files with 1463 additions and 0 deletions
265
src/main/java/one/oth3r/sit/Events.java
Normal file
265
src/main/java/one/oth3r/sit/Events.java
Normal file
|
@ -0,0 +1,265 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.SlabType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Events {
|
||||
private static int tick;
|
||||
public static HashMap<ServerPlayerEntity, Entity> entities = new HashMap<>();
|
||||
public static HashMap<ServerPlayerEntity, Integer> checkPlayers = new HashMap<>();
|
||||
public static boolean checkLogic(ServerPlayerEntity player) {
|
||||
Item mainItem = player.getMainHandStack().getItem();
|
||||
Item offItem = player.getOffHandStack().getItem();
|
||||
if (player.isSneaking()) return false;
|
||||
if (config.mainReq.equals(config.MainReq.empty) && !player.getMainHandStack().isEmpty()) return false;
|
||||
if (config.mainReq.equals(config.MainReq.restrictive)) {
|
||||
if (checkList(config.mainBlacklist,mainItem)) return false;
|
||||
if (!checkList(config.mainWhitelist,mainItem)) {
|
||||
if (config.mainBlock && (mainItem instanceof BlockItem)) return false;
|
||||
if (config.mainFood && mainItem.isFood()) return false;
|
||||
if (config.mainUsable && player.getMainHandStack().isUsedOnRelease()) return false;
|
||||
}
|
||||
}
|
||||
if (config.offReq.equals(config.OffReq.empty) && !player.getOffHandStack().isEmpty()) return false;
|
||||
if (config.offReq.equals(config.OffReq.restrictive)) {
|
||||
if (checkList(config.offBlacklist,offItem)) return false;
|
||||
if (!checkList(config.offWhitelist,offItem)) {
|
||||
if (config.offBlock && (offItem instanceof BlockItem)) return false;
|
||||
if (config.offFood && offItem.isFood()) return false;
|
||||
if (config.offUsable && player.getOffHandStack().isUsedOnRelease()) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean checkList(List<String> list, Item item) {
|
||||
String itemID = Registries.ITEM.getId(item).toString();
|
||||
System.out.println(itemID);
|
||||
return list.contains(itemID);
|
||||
}
|
||||
public static HashMap<String,HashMap<String,Object>> getCustomBlocks() {
|
||||
HashMap<String,HashMap<String,Object>> map = new HashMap<>();
|
||||
int i = 1;
|
||||
for (String s:config.customBlocks) {
|
||||
String[] split = s.split("\\|");
|
||||
HashMap<String,Object> data = new HashMap<>();
|
||||
data.put("block",split[0]);
|
||||
data.put("height",split[1]);
|
||||
data.put("hitbox",split[2]);
|
||||
if (split.length==4) data.put("state",split[3]);
|
||||
map.put(i+"",data);
|
||||
i++;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean checkBlocks(BlockPos pos, World world) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
BlockState blockStateAbove = world.getBlockState(pos.add(0,1,0));
|
||||
Block blockAbove = blockStateAbove.getBlock();
|
||||
System.out.println(blockState);
|
||||
//not the biggest fan but ah well
|
||||
if (blockStateAbove.isFullCube(world,pos.add(0,1,0)) && blockStateAbove.blocksMovement()) return false;
|
||||
else if (blockAbove instanceof StairsBlock || blockAbove instanceof SlabBlock || blockAbove instanceof CarpetBlock) return false;
|
||||
for (Entity entity:entities.values()) if (entity.getBlockPos().equals(pos) || entity.getBlockPos().add(0,1,0).equals(pos)) return false;
|
||||
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 (config.customOn && config.customBlocks.size() != 0) {
|
||||
System.out.println("checking custom");
|
||||
for (HashMap<String,Object> map:getCustomBlocks().values()) {
|
||||
String blockID = Registries.BLOCK.getId(block).toString();
|
||||
if (map.get("block").equals(blockID)) {
|
||||
if (!map.containsKey("state")) return true;
|
||||
String[] states = ((String) map.get("state")).split(",\\s*");
|
||||
boolean matching = true;
|
||||
for (String state:states) {
|
||||
if (state.charAt(0) == '!')
|
||||
if (blockState.toString().contains(state.substring(1))) matching = false;
|
||||
else if (!blockState.toString().contains(state)) matching = false;
|
||||
}
|
||||
return matching;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static void setEntity(BlockPos pos, World world, Entity entity) {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
entity.setCustomName(Text.of(Sit.ENTITY_NAME));
|
||||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.47, pos.getZ() + 0.5, 0, 0);
|
||||
entity.setInvulnerable(true);
|
||||
if (block instanceof StairsBlock) {
|
||||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0);
|
||||
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5));
|
||||
}
|
||||
if (block instanceof SlabBlock) {
|
||||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.27, pos.getZ() + 0.5, 0, 0);
|
||||
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,1,1.5));
|
||||
}
|
||||
if (block instanceof CarpetBlock) {
|
||||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()-.17, pos.getZ() + 0.5, 0, 0);
|
||||
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,0.125,1.5));
|
||||
}
|
||||
if (world.getBlockState(pos).isFullCube(world,pos.add(0,1,0))) {
|
||||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+.78, pos.getZ() + 0.5, 0, 0);
|
||||
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,2,1.5));
|
||||
}
|
||||
if (config.customOn && config.customBlocks.size() != 0) {
|
||||
System.out.println("checking custom sit height");
|
||||
for (HashMap<String,Object> map:getCustomBlocks().values()) {
|
||||
String blockID = Registries.BLOCK.getId(block).toString();
|
||||
if (map.get("block").equals(blockID)) {
|
||||
double input = Math.max(Math.min(Double.parseDouble((String) map.get("height")),1),0);
|
||||
entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY()+input-.22, pos.getZ() + 0.5, 0, 0);
|
||||
entity.setBoundingBox(Box.of(Vec3d.of(pos),1.5,Double.parseDouble((String) map.get("hitbox")),1.5));
|
||||
}
|
||||
}
|
||||
}
|
||||
//change pitch based on if player is sitting below block height or not
|
||||
if (entity.getY() <= pos.getY()+.35) entity.setPitch(90);
|
||||
else entity.setPitch(-90);
|
||||
}
|
||||
public static void register() {
|
||||
UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> {
|
||||
ServerPlayerEntity player = Sit.server.getPlayerManager().getPlayer(pl.getUuid());
|
||||
if (player == null) return ActionResult.PASS;
|
||||
if (hand == net.minecraft.util.Hand.MAIN_HAND && hitResult.getType() == HitResult.Type.BLOCK) {
|
||||
BlockPos pos = hitResult.getBlockPos();
|
||||
//todo idk find bugs and polish
|
||||
if (!checkLogic(player)) return ActionResult.PASS;
|
||||
if (checkBlocks(pos,world)) {
|
||||
if (entities.containsKey(player)) {
|
||||
if (!config.sitWhileSeated) return ActionResult.PASS;
|
||||
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
entities.remove(player);
|
||||
}
|
||||
DisplayEntity.TextDisplayEntity entity = new DisplayEntity.TextDisplayEntity(EntityType.TEXT_DISPLAY,player.getServerWorld());
|
||||
setEntity(pos,world,entity);
|
||||
player.getServerWorld().spawnEntity(entity);
|
||||
player.startRiding(entity);
|
||||
entities.put(player,entity);
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
ServerTickEvents.END_SERVER_TICK.register(minecraftServer -> minecraftServer.execute(Events::cleanUp));
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||
ServerPlayerEntity player = handler.player;
|
||||
checkPlayers.put(player,2);
|
||||
});
|
||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
||||
ServerPlayerEntity player = handler.player;
|
||||
if (entities.containsKey(player)) {
|
||||
if (!config.keepActive) {
|
||||
player.dismountVehicle();
|
||||
entities.get(player).setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
}
|
||||
entities.remove(player);
|
||||
}
|
||||
checkPlayers.remove(player);
|
||||
});
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(s -> {
|
||||
Sit.server = s;
|
||||
Sit.commandManager = s.getCommandManager();
|
||||
});
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> SitCommand.register(dispatcher));
|
||||
}
|
||||
public static void cleanUp() {
|
||||
tick++;
|
||||
if (tick >= 5) {
|
||||
tick = 0;
|
||||
Iterator<Map.Entry<ServerPlayerEntity, Entity>> entityLoop = entities.entrySet().iterator();
|
||||
while (entityLoop.hasNext()) {
|
||||
Map.Entry<ServerPlayerEntity, Entity> entry = entityLoop.next();
|
||||
ServerPlayerEntity player = entry.getKey();
|
||||
Entity entity = entry.getValue();
|
||||
if (player.getVehicle() == null || !player.getVehicle().equals(entity)) {
|
||||
entity.setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
System.out.println("removed..");
|
||||
entityLoop.remove();
|
||||
} else {
|
||||
BlockPos pos = new BlockPos(entity.getBlockX(),(int) Math.floor(player.getY()),entity.getBlockZ());
|
||||
if (entity.getPitch() == 90) pos = new BlockPos(entity.getBlockX(),(int) Math.ceil(player.getY()),entity.getBlockZ());
|
||||
BlockState blockState = player.getWorld().getBlockState(pos);
|
||||
if (blockState.isAir()) {
|
||||
System.out.println(pos);
|
||||
System.out.println(entity.getY());
|
||||
System.out.println("dismount");
|
||||
player.teleport(player.getX(),player.getBlockY()+1,player.getZ());
|
||||
entity.setRemoved(Entity.RemovalReason.DISCARDED);
|
||||
entityLoop.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
Iterator<Map.Entry<ServerPlayerEntity, Integer>> playerCheckLoop = checkPlayers.entrySet().iterator();
|
||||
while (playerCheckLoop.hasNext()) {
|
||||
Map.Entry<ServerPlayerEntity, Integer> entry = playerCheckLoop.next();
|
||||
ServerPlayerEntity player = entry.getKey();
|
||||
int i = entry.getValue();
|
||||
checkPlayers.put(player,i-1);
|
||||
if (i<0) {
|
||||
System.out.println("fail");
|
||||
playerCheckLoop.remove();
|
||||
continue;
|
||||
}
|
||||
System.out.println("trying to add back");
|
||||
if (player.getVehicle() != null) {
|
||||
Entity entity = player.getVehicle();
|
||||
if (entity.getName().getString().equals(Sit.ENTITY_NAME)) {
|
||||
System.out.println("adding back");
|
||||
setEntity(player.getBlockPos().add(0,1,0),player.getServerWorld(),entity);
|
||||
entities.put(player,entity);
|
||||
playerCheckLoop.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ServerPlayerEntity player:checkPlayers.keySet()) {
|
||||
int i = checkPlayers.get(player);
|
||||
checkPlayers.put(player,i-1);
|
||||
if (i<0) {
|
||||
System.out.println("fail");
|
||||
checkPlayers.remove(player);
|
||||
continue;
|
||||
}
|
||||
System.out.println("trying to add back");
|
||||
if (player.getVehicle() != null) {
|
||||
Entity entity = player.getVehicle();
|
||||
if (entity.getName().getString().equals(Sit.ENTITY_NAME)) {
|
||||
System.out.println("adding back");
|
||||
setEntity(player.getBlockPos().add(0,1,0),player.getServerWorld(),entity);
|
||||
entities.put(player,entity);
|
||||
checkPlayers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
src/main/java/one/oth3r/sit/LangReader.java
Normal file
100
src/main/java/one/oth3r/sit/LangReader.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextContent;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LangReader {
|
||||
private static final Map<String, String> languageMap = new HashMap<>();
|
||||
private final String translationKey;
|
||||
private final Object[] placeholders;
|
||||
public LangReader(String translationKey, Object... placeholders) {
|
||||
this.translationKey = translationKey;
|
||||
this.placeholders = placeholders;
|
||||
}
|
||||
public MutableText getTxT() {
|
||||
String translated = getLanguageValue(translationKey);
|
||||
if (placeholders != null && placeholders.length > 0) {
|
||||
//removed all double \\ and replaces with \
|
||||
translated = translated.replaceAll("\\\\\\\\", "\\\\");
|
||||
String regex = "%\\d*\\$?[dfs]";
|
||||
Matcher anyMatch = Pattern.compile(regex).matcher(translated);
|
||||
Matcher endMatch = Pattern.compile(regex+"$").matcher(translated);
|
||||
//Arraylist with all the %(#$)[dfs]
|
||||
ArrayList<String> matches = new ArrayList<>();
|
||||
while (anyMatch.find()) {
|
||||
String match = anyMatch.group();
|
||||
matches.add(match);
|
||||
}
|
||||
//SPLITS the text at each regex and remove the regex
|
||||
String[] parts = translated.split(regex);
|
||||
//if the last element of the array ends with regex, remove it and add an empty string to the end of the array
|
||||
if (endMatch.find()) {
|
||||
String[] newParts = Arrays.copyOf(parts, parts.length + 1);
|
||||
newParts[parts.length] = "";
|
||||
parts = newParts;
|
||||
}
|
||||
//if there are placeholders specified, and the split is more than 1, it will replace %(dfs) with the placeholder objects
|
||||
if (parts.length > 1) {
|
||||
MutableText txt = Text.empty();
|
||||
int i = 0;
|
||||
for (String match : matches) {
|
||||
int get = i;
|
||||
//if the match is numbered, change GET to the number it wants
|
||||
if (match.contains("$")) {
|
||||
match = match.substring(1,match.indexOf('$'));
|
||||
get = Integer.parseInt(match)-1;
|
||||
}
|
||||
if (parts.length != i) txt.append(parts[i]);
|
||||
//convert the obj into txt
|
||||
Object obj = placeholders[get];
|
||||
if (obj instanceof Text) txt.append((Text) obj);
|
||||
else txt.append(String.valueOf(obj));
|
||||
i++;
|
||||
}
|
||||
if (parts.length != i) txt.append(parts[i]);
|
||||
return txt;
|
||||
}
|
||||
}
|
||||
return MutableText.of(TextContent.EMPTY).append(translated);
|
||||
}
|
||||
public static LangReader of(String translationKey, Object... placeholders) {
|
||||
return new LangReader(translationKey, placeholders);
|
||||
}
|
||||
public static void loadLanguageFile() {
|
||||
try {
|
||||
ClassLoader classLoader = Sit.class.getClassLoader();
|
||||
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;
|
||||
}
|
||||
if (inputStream == null) throw new IllegalArgumentException("CANT LOAD THE LANGUAGE FILE. DIRECTIONHUD WILL BREAK.");
|
||||
Scanner scanner = new Scanner(inputStream);
|
||||
String currentLine;
|
||||
while (scanner.hasNextLine()) {
|
||||
currentLine = scanner.nextLine().trim();
|
||||
if (currentLine.startsWith("{") || currentLine.startsWith("}")) {
|
||||
continue;
|
||||
}
|
||||
String[] keyValue = currentLine.split(":", 2);
|
||||
String key = keyValue[0].trim();
|
||||
key = key.substring(1,key.length()-1).replace("\\","");
|
||||
String value = keyValue[1].trim();
|
||||
if (value.endsWith(",")) value = value.substring(0, value.length() - 1);
|
||||
value = value.substring(1,value.length()-1).replace("\\","");
|
||||
languageMap.put(key, value);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static String getLanguageValue(String key) {
|
||||
return languageMap.getOrDefault(key, key);
|
||||
}
|
||||
}
|
196
src/main/java/one/oth3r/sit/ModMenu.java
Normal file
196
src/main/java/one/oth3r/sit/ModMenu.java
Normal file
|
@ -0,0 +1,196 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import dev.isxander.yacl3.api.*;
|
||||
import dev.isxander.yacl3.api.controller.BooleanControllerBuilder;
|
||||
import dev.isxander.yacl3.api.controller.EnumControllerBuilder;
|
||||
import dev.isxander.yacl3.api.controller.StringControllerBuilder;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextColor;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class ModMenu implements ModMenuApi {
|
||||
private static MutableText lang(String key) {
|
||||
return Text.translatable("config.sit."+key);
|
||||
}
|
||||
private static MutableText lang(String key, Object... args) {
|
||||
return Text.translatable("config.sit."+key,args);
|
||||
}
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return parent -> YetAnotherConfigLib.createBuilder()
|
||||
.title(Text.of("Sit!"))
|
||||
.category(ConfigCategory.createBuilder()
|
||||
.name(lang("category.general"))
|
||||
.tooltip(lang("category.general.tooltip"))
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.keep_active"))
|
||||
.description(OptionDescription.of(lang("general.keep_active.description")))
|
||||
.binding(config.defaults.keepActive, () -> config.keepActive, n -> config.keepActive = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.sit_while_seated"))
|
||||
.description(OptionDescription.of(lang("general.sit_while_seated.description")))
|
||||
.binding(config.defaults.sitWhileSeated, () -> config.sitWhileSeated, n -> config.sitWhileSeated = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.group(OptionGroup.createBuilder()
|
||||
.name(lang("general.sittable"))
|
||||
.description(OptionDescription.of(lang("general.sittable.description")))
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.sittable.stairs"))
|
||||
.binding(config.defaults.stairsOn, () -> config.stairsOn, n -> config.stairsOn = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.sittable.slabs"))
|
||||
.binding(config.defaults.slabsOn, () -> config.slabsOn, n -> config.slabsOn = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.sittable.carpets"))
|
||||
.binding(config.defaults.carpetsOn, () -> config.carpetsOn, n -> config.carpetsOn = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.sittable.full_blocks"))
|
||||
.binding(config.defaults.fullBlocksOn, () -> config.fullBlocksOn, n -> config.fullBlocksOn = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("general.sittable.custom"))
|
||||
.description(OptionDescription.of(lang("general.sittable.custom.description")))
|
||||
.binding(config.defaults.customOn, () -> config.customOn, n -> config.customOn = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).onOffFormatter())
|
||||
.build())
|
||||
.build())
|
||||
.group(ListOption.<String>createBuilder()
|
||||
.name(lang("general.sittable_blocks"))
|
||||
.description(OptionDescription.of(
|
||||
lang("general.sittable_blocks.description")
|
||||
.append("\n\n").append(lang("general.sittable_blocks.description_2"))
|
||||
.append(lang("general.sittable_blocks.description_3",
|
||||
lang("general.sittable_blocks.description_3_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))),
|
||||
lang("general.sittable_blocks.description_3_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))),
|
||||
lang("general.sittable_blocks.description_3_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))),
|
||||
lang("general.sittable_blocks.description_3_5").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GOLD)))).styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))
|
||||
.append("\n\n").append(lang("general.sittable_blocks.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))))
|
||||
.append("\n").append(lang("general.sittable_blocks.description_5").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))))
|
||||
.append("\n").append(lang("general.sittable_blocks.description_6").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))))
|
||||
.append("\n").append(lang("general.sittable_blocks.description_7").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GOLD))))
|
||||
.append("\n\n").append(lang("general.sittable_blocks.description_8").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.YELLOW))))))
|
||||
.binding(config.defaults.customBlocks, () -> config.customBlocks, n -> config.customBlocks = n)
|
||||
.controller(StringControllerBuilder::create)
|
||||
.initial("")
|
||||
.build())
|
||||
.build())
|
||||
.category(ConfigCategory.createBuilder()
|
||||
.name(lang("category.main_hand"))
|
||||
.tooltip(lang("category.main_hand.tooltip"))
|
||||
.option(Option.<config.MainReq>createBuilder()
|
||||
.name(lang("hand.requirements"))
|
||||
.description(OptionDescription.of(lang("hand.requirements.description")
|
||||
.append("\n\n").append(lang("hand.requirements.description_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))))
|
||||
.append("\n").append(lang("hand.requirements.description_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))))
|
||||
.append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))))))
|
||||
.binding(config.defaults.mainReq, () -> config.mainReq, n -> config.mainReq = n)
|
||||
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.MainReq.class)
|
||||
.valueFormatter(v -> Text.translatable("config.sit."+v.name().toLowerCase())))
|
||||
.build())
|
||||
.group(OptionGroup.createBuilder()
|
||||
.name(lang("hand.restrictions"))
|
||||
.description(OptionDescription.of(lang("hand.restrictions.description")))
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("hand.restrictions.blocks"))
|
||||
.binding(config.defaults.mainBlock,()-> config.mainBlock,n -> config.mainBlock = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("hand.restrictions.food"))
|
||||
.binding(config.defaults.mainFood,()-> config.mainFood,n -> config.mainFood = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("hand.restrictions.usable"))
|
||||
.description(OptionDescription.of(lang("hand.restrictions.usable.description")))
|
||||
.binding(config.defaults.mainUsable,()-> config.mainUsable,n -> config.mainUsable = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.build())
|
||||
.group(ListOption.<String>createBuilder()
|
||||
.name(lang("hand.whitelist"))
|
||||
.description(OptionDescription.of(lang("hand.whitelist.description")
|
||||
.append("\n\n").append(lang("hand.list.description"))
|
||||
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||
.binding(config.defaults.mainWhitelist, () -> config.mainWhitelist, n -> config.mainWhitelist = n)
|
||||
.controller(StringControllerBuilder::create)
|
||||
.initial("")
|
||||
.build())
|
||||
.group(ListOption.<String>createBuilder()
|
||||
.name(lang("hand.blacklist"))
|
||||
.description(OptionDescription.of(lang("hand.blacklist.description")
|
||||
.append("\n\n").append(lang("hand.list.description"))
|
||||
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||
.binding(config.defaults.mainBlacklist, () -> config.mainBlacklist, n -> config.mainBlacklist = n)
|
||||
.controller(StringControllerBuilder::create)
|
||||
.initial("")
|
||||
.build())
|
||||
.build())
|
||||
.category(ConfigCategory.createBuilder()
|
||||
.name(lang("category.off_hand"))
|
||||
.tooltip(lang("category.off_hand.tooltip"))
|
||||
.option(Option.<config.OffReq>createBuilder()
|
||||
.name(lang("hand.requirements"))
|
||||
.description(OptionDescription.of(lang("hand.requirements.description")
|
||||
.append("\n\n").append(lang("hand.requirements.description_2").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.AQUA))))
|
||||
.append("\n").append(lang("hand.requirements.description_3").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))))
|
||||
.append("\n").append(lang("hand.requirements.description_4").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.RED))))))
|
||||
.binding(config.defaults.offReq, () -> config.offReq, n -> config.offReq = n)
|
||||
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(config.OffReq.class)
|
||||
.valueFormatter(v -> Text.translatable("config.sit."+v.name().toLowerCase())))
|
||||
.build())
|
||||
.group(OptionGroup.createBuilder()
|
||||
.name(lang("hand.restrictions"))
|
||||
.description(OptionDescription.of(lang("hand.restrictions.description")))
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("hand.restrictions.blocks"))
|
||||
.binding(config.defaults.offBlock,()-> config.offBlock,n -> config.offBlock = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("hand.restrictions.food"))
|
||||
.binding(config.defaults.offFood,()-> config.offFood,n -> config.offFood = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.option(Option.<Boolean>createBuilder()
|
||||
.name(lang("hand.restrictions.usable"))
|
||||
.description(OptionDescription.of(lang("hand.restrictions.usable.description")))
|
||||
.binding(config.defaults.offUsable,()-> config.offUsable,n -> config.offUsable = n)
|
||||
.controller(opt -> BooleanControllerBuilder.create(opt).trueFalseFormatter())
|
||||
.build())
|
||||
.build())
|
||||
.group(ListOption.<String>createBuilder()
|
||||
.name(lang("hand.whitelist"))
|
||||
.description(OptionDescription.of(lang("hand.whitelist.description")
|
||||
.append("\n\n").append(lang("hand.list.description"))
|
||||
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||
.binding(config.defaults.offWhitelist, () -> config.offWhitelist, n -> config.offWhitelist = n)
|
||||
.controller(StringControllerBuilder::create)
|
||||
.initial("")
|
||||
.build())
|
||||
.group(ListOption.<String>createBuilder()
|
||||
.name(lang("hand.blacklist"))
|
||||
.description(OptionDescription.of(lang("hand.blacklist.description")
|
||||
.append("\n\n").append(lang("hand.list.description"))
|
||||
.append(lang("hand.list.description_2").styled(style -> style.withItalic(true).withColor(TextColor.fromFormatting(Formatting.GRAY))))))
|
||||
.binding(config.defaults.offBlacklist, () -> config.offBlacklist, n -> config.offBlacklist = n)
|
||||
.controller(StringControllerBuilder::create)
|
||||
.initial("")
|
||||
.build())
|
||||
.build())
|
||||
.build().generateScreen(parent);
|
||||
}
|
||||
}
|
31
src/main/java/one/oth3r/sit/Sit.java
Normal file
31
src/main/java/one/oth3r/sit/Sit.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Sit implements ModInitializer {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("sit");
|
||||
public static final String ENTITY_NAME = "-sit!-entity-";
|
||||
public static MinecraftServer server;
|
||||
public static CommandManager commandManager;
|
||||
public static boolean isClient = true;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
//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();
|
||||
Events.register();
|
||||
}
|
||||
public static MutableText lang(String key, Object... args) {
|
||||
if (isClient) return Text.translatable(key, args);
|
||||
else return LangReader.of(key, args).getTxT();
|
||||
}
|
||||
}
|
66
src/main/java/one/oth3r/sit/SitCommand.java
Normal file
66
src/main/java/one/oth3r/sit/SitCommand.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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.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 java.util.Objects;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SitCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(CommandManager.literal("sit")
|
||||
.requires((commandSource) -> commandSource.hasPermissionLevel(2))
|
||||
.executes((context2) -> command(context2.getSource(), context2.getInput()))
|
||||
.then(CommandManager.argument("args", StringArgumentType.string())
|
||||
.suggests(SitCommand::getSuggestions)
|
||||
.executes((context2) -> command(context2.getSource(), context2.getInput()))));
|
||||
}
|
||||
public static CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
|
||||
ServerPlayerEntity player = Objects.requireNonNull(context.getSource().getPlayer());
|
||||
String[] args = context.getInput().split(" ");
|
||||
builder.suggest("reload");
|
||||
builder.suggest("purgeChairEntities");
|
||||
return builder.buildFuture();
|
||||
}
|
||||
private static int command(ServerCommandSource source, String arg) {
|
||||
ServerPlayerEntity player = source.getPlayer();
|
||||
if (player == null) return 1;
|
||||
//trim all the arguments before the command
|
||||
String keyword = "sit";
|
||||
int index = Integer.MAX_VALUE;
|
||||
if (arg.contains(keyword)) index = arg.indexOf(keyword);
|
||||
//trims the words before the text
|
||||
if (index != Integer.MAX_VALUE) arg = arg.substring(index).trim();
|
||||
String[] args = arg.split(" ");
|
||||
if (args[0].equalsIgnoreCase("sit"))
|
||||
args = arg.replaceFirst("sit ", "").split(" ");
|
||||
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
config.load();
|
||||
player.sendMessage(Sit.lang("key.sit.command.reloaded").styled(style -> style.withColor(TextColor.fromFormatting(Formatting.GREEN))));
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("purgeChairEntities")) {
|
||||
String cmd = "kill @e[type=minecraft:text_display,name=\""+Sit.ENTITY_NAME+"\"]";
|
||||
try {
|
||||
ParseResults<ServerCommandSource> parse =
|
||||
Sit.commandManager.getDispatcher().parse(cmd, player.getCommandSource());
|
||||
Sit.commandManager.getDispatcher().execute(parse);
|
||||
player.sendMessage(Sit.lang("key.sit.command.purged"));
|
||||
} catch (CommandSyntaxException e) {
|
||||
player.sendMessage(Sit.lang("key.sit.command.purged"));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
12
src/main/java/one/oth3r/sit/SitServer.java
Normal file
12
src/main/java/one/oth3r/sit/SitServer.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
|
||||
public class SitServer implements DedicatedServerModInitializer {
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
Sit.isClient = false;
|
||||
config.load();
|
||||
LangReader.loadLanguageFile();
|
||||
}
|
||||
}
|
201
src/main/java/one/oth3r/sit/config.java
Normal file
201
src/main/java/one/oth3r/sit/config.java
Normal file
|
@ -0,0 +1,201 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.text.MutableText;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class config {
|
||||
public static String lang = defaults.lang;
|
||||
public static boolean keepActive = defaults.keepActive;
|
||||
public static boolean sitWhileSeated = defaults.sitWhileSeated;
|
||||
public static boolean stairsOn = defaults.stairsOn;
|
||||
public static boolean slabsOn = defaults.slabsOn;
|
||||
public static boolean carpetsOn = defaults.carpetsOn;
|
||||
public static boolean fullBlocksOn = defaults.fullBlocksOn;
|
||||
public static boolean customOn = defaults.customOn;
|
||||
public static List<String> customBlocks = defaults.customBlocks;
|
||||
enum MainReq {
|
||||
empty,
|
||||
restrictive,
|
||||
none
|
||||
}
|
||||
public static MainReq mainReq = defaults.mainReq;
|
||||
public static boolean mainBlock = defaults.mainBlock;
|
||||
public static boolean mainFood = defaults.mainFood;
|
||||
public static boolean mainUsable = defaults.mainUsable;
|
||||
public static List<String> mainWhitelist = defaults.mainWhitelist;
|
||||
public static List<String> mainBlacklist = defaults.mainBlacklist;
|
||||
enum OffReq {
|
||||
empty,
|
||||
restrictive,
|
||||
none
|
||||
}
|
||||
public static OffReq offReq = defaults.offReq;
|
||||
public static boolean offBlock = defaults.offBlock;
|
||||
public static boolean offFood = defaults.offFood;
|
||||
public static boolean offUsable = defaults.offUsable;
|
||||
public static List<String> offWhitelist = defaults.offWhitelist;
|
||||
public static List<String> offBlacklist = defaults.offBlacklist;
|
||||
public static void resetDefaults() {
|
||||
lang = defaults.lang;
|
||||
keepActive = defaults.keepActive;
|
||||
sitWhileSeated = defaults.sitWhileSeated;
|
||||
stairsOn = defaults.stairsOn;
|
||||
slabsOn = defaults.slabsOn;
|
||||
carpetsOn = defaults.carpetsOn;
|
||||
fullBlocksOn = defaults.fullBlocksOn;
|
||||
customOn = defaults.customOn;
|
||||
customBlocks = defaults.customBlocks;
|
||||
mainReq = defaults.mainReq;
|
||||
mainBlock = defaults.mainBlock;
|
||||
mainFood = defaults.mainFood;
|
||||
mainUsable = defaults.mainUsable;
|
||||
mainWhitelist = defaults.mainWhitelist;
|
||||
mainBlacklist = defaults.mainBlacklist;
|
||||
offReq = defaults.offReq;
|
||||
offBlock = defaults.offBlock;
|
||||
offFood = defaults.offFood;
|
||||
offUsable = defaults.offUsable;
|
||||
offWhitelist = defaults.offWhitelist;
|
||||
offBlacklist = defaults.offBlacklist;
|
||||
save();
|
||||
}
|
||||
public static File configFile() {
|
||||
return new File(FabricLoader.getInstance().getConfigDir().toFile()+"/Sit!.properties");
|
||||
}
|
||||
public static void load() {
|
||||
if (!configFile().exists() || !configFile().canRead()) {
|
||||
save();
|
||||
load();
|
||||
return;
|
||||
}
|
||||
try (FileInputStream fileStream = new FileInputStream(configFile())) {
|
||||
Properties properties = new Properties();
|
||||
properties.load(fileStream);
|
||||
loadVersion(properties,(String) properties.computeIfAbsent("version", a -> defaults.version+""));
|
||||
save();
|
||||
} catch (Exception f) {
|
||||
//read fail
|
||||
f.printStackTrace();
|
||||
resetDefaults();
|
||||
}
|
||||
}
|
||||
public static void loadVersion(Properties properties, String version) {
|
||||
Type mapType = new TypeToken<ArrayList<String>>() {}.getType();
|
||||
lang = (String) properties.computeIfAbsent("lang", a -> defaults.lang+"");
|
||||
//CONFIG
|
||||
keepActive = Boolean.parseBoolean((String) properties.computeIfAbsent("keep-active", a -> defaults.keepActive+""));
|
||||
sitWhileSeated = Boolean.parseBoolean((String) properties.computeIfAbsent("sit-while-seated", a -> defaults.sitWhileSeated+""));
|
||||
stairsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("stairs", a -> defaults.stairsOn+""));
|
||||
slabsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("slabs", a -> defaults.slabsOn+""));
|
||||
carpetsOn = Boolean.parseBoolean((String) properties.computeIfAbsent("carpets", a -> defaults.carpetsOn+""));
|
||||
fullBlocksOn = Boolean.parseBoolean((String) properties.computeIfAbsent("full-blocks", a -> defaults.fullBlocksOn+""));
|
||||
customOn = Boolean.parseBoolean((String) properties.computeIfAbsent("custom", a -> defaults.customOn+""));
|
||||
customBlocks = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("custom-blocks", a -> defaults.customBlocks+""),mapType);
|
||||
mainReq = MainReq.valueOf((String) properties.computeIfAbsent("main-hand-requirement", a -> defaults.mainReq+""));
|
||||
mainBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-block", a -> defaults.mainBlock+""));
|
||||
mainFood = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-food", a -> defaults.mainFood+""));
|
||||
mainUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("main-hand-usable", a -> defaults.mainUsable +""));
|
||||
mainWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("main-hand-whitelist", a -> defaults.mainWhitelist+""),mapType);
|
||||
mainBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("main-hand-blacklist", a -> defaults.mainBlacklist+""),mapType);
|
||||
offReq = OffReq.valueOf((String) properties.computeIfAbsent("off-hand-requirement", a -> defaults.offReq+""));
|
||||
offBlock = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-block", a -> defaults.offBlock+""));
|
||||
offFood = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-food", a -> defaults.offFood+""));
|
||||
offUsable = Boolean.parseBoolean((String) properties.computeIfAbsent("off-hand-usable", a -> defaults.offUsable +""));
|
||||
offWhitelist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("off-hand-whitelist", a -> defaults.offWhitelist+""),mapType);
|
||||
offBlacklist = new Gson().fromJson((String)
|
||||
properties.computeIfAbsent("off-hand-blacklist", a -> defaults.offBlacklist+""),mapType);
|
||||
}
|
||||
public static MutableText lang(String key, Object... args) {
|
||||
LangReader.loadLanguageFile();
|
||||
return LangReader.of("config.sit."+key, args).getTxT();
|
||||
}
|
||||
public static void save() {
|
||||
try (var file = new FileOutputStream(configFile(), false)) {
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
file.write("# Sit! Config\n".getBytes());
|
||||
file.write(("version="+defaults.version).getBytes());
|
||||
file.write(("\n# all available languages: en_us").getBytes());
|
||||
file.write(("\nlang=" + lang).getBytes());
|
||||
file.write(("\n\n# "+lang("general.keep_active.description").getString()).getBytes());
|
||||
file.write(("\nkeep-active=" + keepActive).getBytes());
|
||||
file.write(("\n# "+lang("general.sit_while_seated.description").getString()).getBytes());
|
||||
file.write(("\nsit-while-seated=" + sitWhileSeated).getBytes());
|
||||
file.write(("\n# "+lang("general.sittable.description").getString()).getBytes());
|
||||
file.write(("\nstairs=" + stairsOn).getBytes());
|
||||
file.write(("\nslabs=" + slabsOn).getBytes());
|
||||
file.write(("\ncarpets=" + carpetsOn).getBytes());
|
||||
file.write(("\nfull-blocks=" + fullBlocksOn).getBytes());
|
||||
file.write(("\ncustom=" + customOn).getBytes());
|
||||
file.write(("\n# "+lang("general.sittable_blocks.description")
|
||||
.append("\n# ").append(lang("general.sittable_blocks.description_2"))
|
||||
.append(lang("general.sittable_blocks.description_3",
|
||||
lang("general.sittable_blocks.description_3_2"),
|
||||
lang("general.sittable_blocks.description_3_3"),
|
||||
lang("general.sittable_blocks.description_3_4"),
|
||||
lang("general.sittable_blocks.description_3_5")))
|
||||
.append("\n# ").append(lang("general.sittable_blocks.description_4"))
|
||||
.append("\n# ").append(lang("general.sittable_blocks.description_5"))
|
||||
.append("\n# ").append(lang("general.sittable_blocks.description_6"))
|
||||
.append("\n# ").append(lang("general.sittable_blocks.description_7"))
|
||||
.append("\n# ").append(lang("general.sittable_blocks.description_8")).getString()).getBytes());
|
||||
file.write(("\ncustom-blocks="+gson.toJson(customBlocks)).getBytes());
|
||||
file.write(("\n\n# "+lang("hand.requirements.description")
|
||||
.append("\n# ").append(lang("hand.requirements.description_2"))
|
||||
.append("\n# ").append(lang("hand.requirements.description_3"))
|
||||
.append("\n# ").append(lang("hand.requirements.description_4")).getString()).getBytes());
|
||||
file.write(("\nmain-hand-requirement=" + mainReq).getBytes());
|
||||
file.write(("\nmain-hand-block=" + mainBlock).getBytes());
|
||||
file.write(("\nmain-hand-food=" + mainFood).getBytes());
|
||||
file.write(("\nmain-hand-usable=" + mainUsable).getBytes());
|
||||
file.write(("\nmain-hand-whitelist="+gson.toJson(mainWhitelist)).getBytes());
|
||||
file.write(("\nmain-hand-blacklist="+gson.toJson(mainBlacklist)).getBytes());
|
||||
file.write(("\noff-hand-requirement=" + offReq).getBytes());
|
||||
file.write(("\noff-hand-block=" + offBlock).getBytes());
|
||||
file.write(("\noff-hand-food=" + offFood).getBytes());
|
||||
file.write(("\noff-hand-usable=" + offUsable).getBytes());
|
||||
file.write(("\noff-hand-whitelist="+gson.toJson(offWhitelist)).getBytes());
|
||||
file.write(("\noff-hand-blacklist="+gson.toJson(offBlacklist)).getBytes());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static class defaults {
|
||||
public static String version = "v1.0";
|
||||
public static String lang = "en_us";
|
||||
public static boolean keepActive = true;
|
||||
public static boolean sitWhileSeated = true;
|
||||
public static boolean stairsOn = true;
|
||||
public static boolean slabsOn = true;
|
||||
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|.5|lit=false","minecraft:soul_campfire|.46|.5|lit=false");
|
||||
public static MainReq mainReq = MainReq.empty;
|
||||
public static boolean mainBlock = false;
|
||||
public static boolean mainFood = false;
|
||||
public static boolean mainUsable = false;
|
||||
public static List<String> mainWhitelist = new ArrayList<>();
|
||||
public static List<String> mainBlacklist = new ArrayList<>();
|
||||
public static OffReq offReq = OffReq.restrictive;
|
||||
public static boolean offBlock = true;
|
||||
public static boolean offFood = false;
|
||||
public static boolean offUsable = true;
|
||||
public static List<String> offWhitelist = List.of("minecraft:torch","minecraft:soul_torch");
|
||||
public static List<String> offBlacklist = new ArrayList<>();
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/sit/icon.png
Normal file
BIN
src/main/resources/assets/sit/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
55
src/main/resources/assets/sit/lang/en_us.json
Normal file
55
src/main/resources/assets/sit/lang/en_us.json
Normal file
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"config.sit.empty": "Empty",
|
||||
"config.sit.restrictive": "Restrictive",
|
||||
"config.sit.none": "None",
|
||||
"config.sit.category.general": "General",
|
||||
"config.sit.category.general.tooltip": "General settings",
|
||||
"config.sit.category.main_hand": "Main Hand",
|
||||
"config.sit.category.main_hand.tooltip": "Main hand settings",
|
||||
"config.sit.category.off_hand": "Off Hand",
|
||||
"config.sit.category.off_hand.tooltip": "Off hand settings",
|
||||
"config.sit.general.keep_active": "Keep Active",
|
||||
"config.sit.general.keep_active.description": "Keeps the entities active even when logging off / shutting down",
|
||||
"config.sit.general.sittable": "Sittable Blocks",
|
||||
"config.sit.general.sittable.description": "Toggle the ability to sit on different block types.",
|
||||
"config.sit.general.sit_while_seated": "Sit While Seated",
|
||||
"config.sit.general.sit_while_seated.description": "Toggle the ability to sit on other blocks while already being seated on one.",
|
||||
"config.sit.general.sittable.stairs": "Stairs",
|
||||
"config.sit.general.sittable.slabs": "Slabs",
|
||||
"config.sit.general.sittable.carpets": "Carpets",
|
||||
"config.sit.general.sittable.full_blocks": "Full Blocks",
|
||||
"config.sit.general.sittable.custom": "Custom",
|
||||
"config.sit.general.sittable.custom.description": "Enables adding custom blocks to sit on.",
|
||||
"config.sit.general.sittable_blocks": "Custom Sittable Blocks",
|
||||
"config.sit.general.sittable_blocks.description": "Add custom sittable blocks!",
|
||||
"config.sit.general.sittable_blocks.description_2": "Example: ",
|
||||
"config.sit.general.sittable_blocks.description_3": "\"%s|%s|%s|%s\"",
|
||||
"config.sit.general.sittable_blocks.description_3_2": "minecraft:campfire",
|
||||
"config.sit.general.sittable_blocks.description_3_3": ".255",
|
||||
"config.sit.general.sittable_blocks.description_3_4": "1",
|
||||
"config.sit.general.sittable_blocks.description_3_5": "lit=false",
|
||||
"config.sit.general.sittable_blocks.description_4": "First entry: custom block",
|
||||
"config.sit.general.sittable_blocks.description_5": "Second entry: sitting height (number from 0-1 eg 0.52)",
|
||||
"config.sit.general.sittable_blocks.description_6": "Third entry: hitbox size (where the player spawns above the entity when dismounting)",
|
||||
"config.sit.general.sittable_blocks.description_7": "Fourth entry (optional): required blockstate to sit (Put a \"!\" to exclude blockstates)",
|
||||
"config.sit.general.sittable_blocks.description_8": "Separate different entries with \"|\"!",
|
||||
"config.sit.hand.requirements": "Requirements",
|
||||
"config.sit.hand.requirements.description": "Hand requirements for sitting.",
|
||||
"config.sit.hand.requirements.description_2": "Empty = hand has to be empty",
|
||||
"config.sit.hand.requirements.description_3": "Restrictive = set restrictions for hand state",
|
||||
"config.sit.hand.requirements.description_4": "None = can sit whenever",
|
||||
"config.sit.hand.restrictions": "Restrictions",
|
||||
"config.sit.hand.restrictions.description": "Toggle preset hand restrictions for sitting.",
|
||||
"config.sit.hand.restrictions.blocks": "Blocks",
|
||||
"config.sit.hand.restrictions.food": "Food",
|
||||
"config.sit.hand.restrictions.usable": "Usable",
|
||||
"config.sit.hand.restrictions.usable.description": "eg. bows, tridents, shield",
|
||||
"config.sit.hand.whitelist": "Whitelist",
|
||||
"config.sit.hand.whitelist.description": "Make a custom whitelist for items that the player can use to sit with.",
|
||||
"config.sit.hand.blacklist": "Blacklist",
|
||||
"config.sit.hand.blacklist.description": "Make a custom blacklist for items that the player can't use to sit with.",
|
||||
"config.sit.hand.list.description": "Example: ",
|
||||
"config.sit.hand.list.description_2": "\"minecraft:torch\"",
|
||||
"key.sit.command.reloaded": "Reloaded the config!",
|
||||
"key.sit.command.purged": "Purged all active chair entities!"
|
||||
}
|
41
src/main/resources/fabric.mod.json
Normal file
41
src/main/resources/fabric.mod.json
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "sit",
|
||||
"version": "${version}",
|
||||
"name": "Sit!",
|
||||
"description": "Adds sitting to minecraft! Endless customizability for hand restrictions and sittable blocks.",
|
||||
"authors": [
|
||||
"Oth3r"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://modrinth.com/mod/sit!",
|
||||
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||
},
|
||||
"license": "CC0-1.0",
|
||||
"icon": "assets/sit/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"one.oth3r.sit.Sit"
|
||||
],
|
||||
"server": [
|
||||
"one.oth3r.sit.SitServer"
|
||||
],
|
||||
"modmenu": [
|
||||
"one.oth3r.sit.ModMenu"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"sit.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.14.21",
|
||||
"minecraft": "~1.20.1",
|
||||
"java": ">=17",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
"yet-another-config-lib": "*",
|
||||
"modmenu": "*"
|
||||
}
|
||||
}
|
11
src/main/resources/sit.mixins.json
Normal file
11
src/main/resources/sit.mixins.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "one.oth3r.sit.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue