Merge branch '1.21.4' into 1.21.1

# Conflicts:
#	gradle.properties
#	src/main/java/one/oth3r/sit/SitClient.java
This commit is contained in:
Oth3r 2025-06-27 17:41:29 -05:00
commit 620ff81c37
Failed to generate hash of commit
19 changed files with 127 additions and 282 deletions

View file

@ -0,0 +1,16 @@
package one.oth3r.sit.utl;
import one.oth3r.otterlib.chat.CTxT;
import one.oth3r.sit.file.FileData;
import java.awt.*;
public class Chat {
public static CTxT tag() {
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
}
public static CTxT lang(String key, Object... args) {
return FileData.getLangReader().dynamicTranslatable(key, args);
}
}

View file

@ -4,14 +4,13 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import one.oth3r.otterlib.base.OtterLogger;
import java.util.HashMap;
public class Data {
public static final String MOD_ID = "sit-oth3r";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final OtterLogger LOGGER = new OtterLogger(MOD_ID);
public static final String CONFIG_DIR = FabricLoader.getInstance().getConfigDir().toFile()+"/sit!/";

View file

@ -23,7 +23,6 @@ import net.minecraft.util.ActionResult;
import one.oth3r.sit.SitClient;
import one.oth3r.sit.command.SitCommand;
import one.oth3r.sit.file.FileData;
import one.oth3r.sit.file.LangReader;
import one.oth3r.sit.file.SittingConfig;
import one.oth3r.sit.packet.SitPayloads;
import org.lwjgl.glfw.GLFW;
@ -78,7 +77,7 @@ public class Events {
player.networkHandler.sendCommand("sit");
} else {
// unsupported server message if not in a Sit! server
player.sendMessage(Utl.lang("sit!.chat.unsupported")
player.sendMessage(Chat.lang("sit!.chat.unsupported")
.color(Color.RED).b(), true);
}
}
@ -104,7 +103,7 @@ public class Events {
ServerPlayNetworking.send(context.player(),new SitPayloads.ResponsePayload(SitPayloads.ResponsePayload.VERSION));
// log the receiving of the packet from the player
Data.LOGGER.info(Utl.lang("sit!.console.player_settings",context.player().getName().getString()).toString());
Data.LOGGER.info(Chat.lang("sit!.console.player_settings",context.player().getName().getString()).toString());
})));
}
@ -114,7 +113,7 @@ public class Events {
// only update when needed
if (!Data.isSupportedServer()) {
Data.setSupportedServer(true);
Data.LOGGER.info(Utl.lang("sit!.console.connected",payload.value()).toString());
Data.LOGGER.info(Chat.lang("sit!.console.connected",payload.value()).toString());
}
}));
}
@ -172,7 +171,6 @@ public class Events {
private static void serverLifecycle() {
ServerLifecycleEvents.SERVER_STARTED.register(s -> {
Data.setServer(s);
LangReader.loadLanguageFile();
// right click on block event
UseBlockCallback.EVENT.register((pl, world, hand, hitResult) -> {
@ -192,7 +190,7 @@ public class Events {
ParseResults<ServerCommandSource> parse = dispatcher.parse("sit", player.getCommandSource());
dispatcher.execute(parse);
} catch (CommandSyntaxException e) {
Data.LOGGER.error("Error executing sit command for player {}", player.getName().getString());
Data.LOGGER.error("Error executing sit command for player %s", player.getName().getString());
}
}

View file

@ -201,7 +201,6 @@ public class Logic {
public static void reload() {
FileData.loadFiles();
FileData.saveFiles();
LangReader.loadLanguageFile();
}
/**
@ -228,11 +227,11 @@ public class Logic {
Formatting messageColor = config.getEnabled()?Formatting.GREEN:Formatting.RED;
// send the player the actionbar message
return Utl.lang("sit!.chat.toggle_sit",
Utl.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b();
return Chat.lang("sit!.chat.toggle_sit",
Chat.lang(messageKey).color(config.getEnabled()? Color.GREEN : Color.RED)).b();
} else {
// unsupported server message if not in a Sit! server
return Utl.lang("sit!.chat.unsupported")
return Chat.lang("sit!.chat.unsupported")
.color(Color.RED).b();
}
}

View file

@ -59,46 +59,6 @@ public class Utl {
return Data.getSitEntities().values().stream().noneMatch(entity -> entity.getBlockPos().equals(pos));
}
public static class Num {
public static boolean isInt(String string) {
try {
Integer.parseInt(string);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
public static Integer toInt(String s) {
// return an int no matter what
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
try {
return (int) Double.parseDouble(s);
} catch (NumberFormatException e2) {
return 0;
}
}
}
public static boolean isNum(String s) {
// checks if int or a double
try {
Integer.parseInt(s);
return true;
} catch (NumberFormatException e1) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException e2) {
return false;
}
}
}
}
public static final double HALF_BLOCK = 0.5;
public static final double CARPET = 0.062;
@ -320,58 +280,14 @@ public class Utl {
// send a message if needed
if (message) {
player.sendMessage(messageTag()
.append(lang("sit!.chat.purged",lang("sit!.chat.purged.total",count).color(Color.gray).b()).color(Color.GREEN)).b());
player.sendMessage(Chat.tag()
.append(Chat.lang("sit!.chat.purged",
Chat.lang("sit!.chat.purged.total",count).color(Color.gray).b()
).color(Color.GREEN)).b());
}
}
}
public static CTxT messageTag() {
return new CTxT("Sit!").btn(true).color(Color.decode("#c400ff")).append(" ");
}
/**
* gets a MutableText using the language key, if on server, using the custom lang reader
*/
public static CTxT lang(String key, Object... args) {
if (Data.isClient()) {
// we have to first convert all the CTxT's to the built version because minecraft lang reader doesn't know how to process it
// make a array with the same size of the args
Object[] fixedArgs = new Object[args.length];
// for every arg, build & add if CTxT or just add if not
for (var i = 0; i < args.length; i++) {
if (args[i] instanceof CTxT) fixedArgs[i] = ((CTxT) args[i]).b();
else fixedArgs[i] = args[i];
}
// return the translated text
return new CTxT(Text.translatable(key,fixedArgs));
}
else return LangReader.of(key, args).getTxT();
}
public static class Enum {
public static <T extends java.lang.Enum<T>> T get(Object enumString, Class<T> enumType) {
return get(enumString,enumType,enumType.getEnumConstants()[0]);
}
/**
* gets an enum from a string without returning null
* @param enumString the string of the enum
* @param enumType the class of enums
* @param defaultEnum the enum to return if a match isn't found
* @return an enum, if there isn't a match, it returns the first enum
*/
public static <T extends java.lang.Enum<T>> T get(Object enumString, Class<T> enumType, T defaultEnum) {
T[] values = enumType.getEnumConstants();
for (T all : values) {
// check if there is a match for any of the enum names
if (enumString.toString().equals(all.name())) return all;
}
// if there's no match return the first entry
return defaultEnum;
}
}
/**
* sends the settings packets to the server, if client & in game
*/