Merge branch 'refs/heads/master' into 1.20-1.20.1

# Conflicts:
#	gradle.properties
#	src/main/resources/fabric.mod.json
This commit is contained in:
Oth3r 2024-04-29 12:37:30 -05:00
commit 05eaedf503
7 changed files with 49 additions and 56 deletions

View file

@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}
@ -13,6 +13,7 @@ base {
repositories {
maven { url "https://maven.terraformersmc.com/releases/" }
maven { url "https://maven.isxander.dev/releases" }
maven { url "https://maven.isxander.dev/snapshots" }
}
dependencies {
@ -23,11 +24,7 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modImplementation ("dev.isxander.yacl:yet-another-config-lib-fabric:${project.yacl_version}") {
exclude(group: "org.quiltmc.parsers")
exclude(group: "com.twelvemonkeys.common")
exclude(group: "com.twelvemonkeys.imageio")
}
modImplementation ("dev.isxander:yet-another-config-lib:${project.yacl_version}")
}
processResources {

View file

@ -16,4 +16,4 @@ archives_base_name=sit!
# Dependencies
fabric_version=0.91.0+1.20.1
modmenu_version=7.0.0
yacl_version=3.2.1+1.20
yacl_version=3.4.1+1.20.1-fabric

View file

@ -207,7 +207,7 @@ public class ModMenu implements ModMenuApi {
*/
public static boolean yaclCheck() {
try {
Class.forName("dev.isxander.yacl3.platform.fabric.YACLPlatformImpl");
Class.forName("dev.isxander.yacl3.platform.Env");
return true;
} catch (ClassNotFoundException e) {
return false;

View file

@ -1,35 +0,0 @@
package one.oth3r.sit;
import io.netty.buffer.ByteBuf;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class PacketBuilder {
public static final String SETTINGS = "settings_v1.0";
private final String message;
private final PacketByteBuf packetByteBuf = PacketByteBufs.create();
public PacketBuilder(ByteBuf buf) {
// Read any data sent in the packet
message = buf.toString(StandardCharsets.UTF_8);
packetByteBuf.writeBytes(buf);
}
public PacketBuilder(String message) {
this.message = message;
packetByteBuf.writeBytes(ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)).array());
}
public static Identifier getIdentifier() {
// only 1 packet rn
return new Identifier(Sit.MOD_ID, SETTINGS);
}
public void send() {
ClientPlayNetworking.send(getIdentifier(), packetByteBuf);
}
public String getMessage() {
return this.message;
}
}

View file

@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
@ -12,6 +13,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import one.oth3r.sit.file.Config;
import one.oth3r.sit.packet.CustomPayloads;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -35,17 +37,15 @@ public class Sit implements ModInitializer {
Config.load();
Events.register();
//PACKETS
ServerPlayNetworking.registerGlobalReceiver(PacketBuilder.getIdentifier(),
(server, player, handler, buf, responseSender) -> {
// copy to not throw errors
PacketBuilder packet = new PacketBuilder(buf.copy());
server.execute(() -> {
Type hashMapToken = new TypeToken<HashMap<String, Object>>() {}.getType();
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
playerSettings.put(player,gson.fromJson(packet.getMessage(),hashMapToken));
});
});
PayloadTypeRegistry.playC2S().register(CustomPayloads.SettingsPayload.ID, CustomPayloads.SettingsPayload.CODEC);
ServerPlayNetworking.registerGlobalReceiver(CustomPayloads.SettingsPayload.ID,((payload, context) -> server.execute(() -> {
Type hashMapToken = new TypeToken<HashMap<String, Object>>() {}.getType();
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
playerSettings.put(context.player(),gson.fromJson(payload.value(),hashMapToken));
})));
}
public static MutableText lang(String key, Object... args) {
if (isClient) return Text.translatable(key, args);
else return LangReader.of(key, args).getTxT();

View file

@ -4,6 +4,9 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.network.packet.CustomPayload;
import one.oth3r.sit.packet.CustomPayloads;
public class SitClient implements ClientModInitializer {
public static boolean inGame = false;
@ -13,13 +16,14 @@ public class SitClient implements ClientModInitializer {
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
inGame = true;
// send a data packet whenever joining a server
client.execute(SitClient::sendPackets);
ClientPlayNetworking.send(sendPackets());
});
// reset inGame
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> inGame = false);
}
public static void sendPackets() {
public static CustomPayload sendPackets() {
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
new PacketBuilder(gson.toJson(Utl.HandSettings.getHandSettings())).send();
return new CustomPayloads.SettingsPayload(gson.toJson(Utl.HandSettings.getHandSettings()));
}
}

View file

@ -0,0 +1,27 @@
package one.oth3r.sit.packet;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;
import one.oth3r.sit.Sit;
public class CustomPayloads {
public record SettingsPayload(String value) implements CustomPayload {
public static final Id<SettingsPayload> ID = new Id<>(new Identifier(Sit.MOD_ID,"settings_v1.1"));
public static final PacketCodec<RegistryByteBuf, SettingsPayload> CODEC = PacketCodecs.STRING.xmap(SettingsPayload::new, SettingsPayload::value).cast();
@Override
public Id<SettingsPayload> getId() {
return ID;
}
@Override
public String value() {
return value;
}
}
}