From b7b7b5ed31b858f967d60295050684066ef29d49 Mon Sep 17 00:00:00 2001 From: Sakura Ryoko Date: Fri, 25 Oct 2024 14:00:39 -0400 Subject: [PATCH] trying to fix the placement bug xD --- gradle.properties | 2 +- .../java/ch/endte/syncmatica/Feature.java | 3 +- .../communication/CommunicationManager.java | 19 +++++- .../ch/endte/syncmatica/data/FileStorage.java | 6 +- .../syncmatica/data/ServerPlacement.java | 64 ++++++++++++++++-- .../litematica/LitematicManager.java | 66 +++++++++++++++++-- .../syncmatica/litematica/gui/IGuiBase.java | 9 +++ .../WidgetListSyncmaticaServerPlacement.java | 20 ++++++ .../litematica_mixin/MixinGuiBase.java | 6 +- .../MixinGuiPlacementConfiguration.java | 3 +- .../MixinSchematicPlacement.java | 4 +- .../network/actor/ActorClientPlayHandler.java | 5 +- .../network/handler/ClientPlayHandler.java | 10 ++- .../assets/syncmatica/lang/en_us.json | 2 + .../assets/syncmatica/lang/zh_cn.json | 52 ++++++++------- .../assets/syncmatica/lang/zh_tw.json | 52 ++++++++------- .../syncmatica.litematica_mixin.json | 2 +- src/main/resources/syncmatica.mixin.json | 2 +- 18 files changed, 248 insertions(+), 79 deletions(-) create mode 100644 src/main/java/ch/endte/syncmatica/litematica/gui/IGuiBase.java diff --git a/gradle.properties b/gradle.properties index bec71e360..db417652a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ mod_name = Syncmatica mod_file_name = syncmatica-fabric # Mod Version -mod_version = 0.3.12-sakura.8 +mod_version = 0.3.12-sakura.9 # Dependencies (malilib, litematica) #malilib_fileid=4946328 diff --git a/src/main/java/ch/endte/syncmatica/Feature.java b/src/main/java/ch/endte/syncmatica/Feature.java index 2d44769b6..f7b2585f3 100644 --- a/src/main/java/ch/endte/syncmatica/Feature.java +++ b/src/main/java/ch/endte/syncmatica/Feature.java @@ -8,7 +8,8 @@ public enum Feature { MESSAGE, // ability to send messages to display from server to client QUOTA, // quota on client uploads to the server DEBUG, // ability to configure debugging - CORE_EX; // extended basic features - such as who owns a placement and subregion sharing + CORE_EX, // extended basic features - such as who owns a placement and subregion sharing + VERSION; // extended version metadata public static Feature fromString(final String s) { for (final Feature f : Feature.values()) { diff --git a/src/main/java/ch/endte/syncmatica/communication/CommunicationManager.java b/src/main/java/ch/endte/syncmatica/communication/CommunicationManager.java index d032cd3bd..168651768 100644 --- a/src/main/java/ch/endte/syncmatica/communication/CommunicationManager.java +++ b/src/main/java/ch/endte/syncmatica/communication/CommunicationManager.java @@ -88,7 +88,7 @@ public void putMetaData(final ServerPlacement metaData, final PacketByteBuf buf, { buf.writeUuid(metaData.getId()); - buf.writeString(SyncmaticaUtil.sanitizeFileName(metaData.getName())); + buf.writeString(SyncmaticaUtil.sanitizeFileName(metaData.getFileName())); buf.writeUuid(metaData.getHash()); if (exchangeTarget.getFeatureSet().hasFeature(Feature.CORE_EX)) @@ -98,6 +98,10 @@ public void putMetaData(final ServerPlacement metaData, final PacketByteBuf buf, buf.writeUuid(metaData.getLastModifiedBy().uuid); buf.writeString(metaData.getLastModifiedBy().getName()); } + if (exchangeTarget.getFeatureSet().hasFeature(Feature.VERSION)) { + buf.writeVarInt(metaData.getLitematicVersion()); + buf.writeVarInt(metaData.getDataVersion()); + } putPositionData(metaData, buf, exchangeTarget); } @@ -158,7 +162,18 @@ public ServerPlacement receiveMetaData(final PacketByteBuf buf, final ExchangeTa ); } - final ServerPlacement placement = new ServerPlacement(id, fileName, hash, owner); + ServerPlacement placement; + int litematicVersion; + int dataVersion; + + if (exchangeTarget.getFeatureSet().hasFeature(Feature.VERSION)) { + litematicVersion = buf.readVarInt(); + dataVersion = buf.readVarInt(); + placement = new ServerPlacement(id, fileName, hash, owner, litematicVersion, dataVersion); + } else { + placement = new ServerPlacement(id, fileName, hash, owner); + } + placement.setLastModifiedBy(lastModifiedBy); receivePositionData(placement, buf, exchangeTarget); diff --git a/src/main/java/ch/endte/syncmatica/data/FileStorage.java b/src/main/java/ch/endte/syncmatica/data/FileStorage.java index 42e7d6ed3..6e6be8986 100644 --- a/src/main/java/ch/endte/syncmatica/data/FileStorage.java +++ b/src/main/java/ch/endte/syncmatica/data/FileStorage.java @@ -96,6 +96,10 @@ private File getSchematicPath(final ServerPlacement placement) { if (context.isServer()) { return new File(litematicPath, placement.getHash().toString() + ".litematic"); } - return new File(litematicPath, placement.getName() + ".litematic"); + if (placement.getFileName().contains(".litematic")) { + return new File(litematicPath, placement.getFileName()); + } else { + return new File(litematicPath, placement.getFileName() + ".litematic"); + } } } diff --git a/src/main/java/ch/endte/syncmatica/data/ServerPlacement.java b/src/main/java/ch/endte/syncmatica/data/ServerPlacement.java index c3e27032e..c8cdac015 100644 --- a/src/main/java/ch/endte/syncmatica/data/ServerPlacement.java +++ b/src/main/java/ch/endte/syncmatica/data/ServerPlacement.java @@ -32,18 +32,28 @@ public class ServerPlacement { private SubRegionData subRegionData = new SubRegionData(); + // Feature.VERSION + private int dataVersion; + private int litematicVersion; + private SyncmaticaMaterialList matList; - public ServerPlacement(final UUID id, final String fileName, final UUID hashValue, final PlayerIdentifier owner) { + public ServerPlacement(final UUID id, final String fileName, final UUID hashValue, final PlayerIdentifier owner, int litematicVersion, int dataVersion) { this.id = id; this.fileName = fileName; this.hashValue = hashValue; this.owner = owner; - lastModifiedBy = owner; + this.lastModifiedBy = owner; + this.litematicVersion = litematicVersion; + this.dataVersion = dataVersion; } public ServerPlacement(final UUID id, final File file, final PlayerIdentifier owner) { - this(id, removeExtension(file), generateHash(file), owner); + this(id, removeExtension(file), generateHash(file), owner, -1, -1); + } + + public ServerPlacement(UUID id, String fileName, UUID hash, PlayerIdentifier owner) { + this(id, fileName, hash, owner, -1, -1); } public UUID getId() { @@ -51,7 +61,15 @@ public UUID getId() { } public String getName() { - return fileName; + if (this.getFileName().contains(".")) { + return removeExtension(this.getFileName()); + } + + return this.getFileName(); + } + + public String getFileName() { + return this.fileName; } public UUID getHash() { @@ -78,6 +96,17 @@ public BlockMirror getMirror() { return mirror; } + // Feature.VERSION + public int getLitematicVersion() { return litematicVersion; } + + public int getDataVersion() { return dataVersion; } + + public ServerPlacement setVersion(final int litematicVersion, final int dataVersion) { + this.litematicVersion = litematicVersion; + this.dataVersion = dataVersion; + return this; + } + public ServerPlacement move(final String dimensionId, final BlockPos origin, final BlockRotation rotation, final BlockMirror mirror) { move(new ServerPosition(origin, dimensionId), rotation, mirror); return this; @@ -121,13 +150,19 @@ public ServerPlacement setMaterialList(final SyncmaticaMaterialList matList) { return this; } - private static String removeExtension(final File file) { + public static String removeExtension(final File file) { // source stackoverflow final String fileName = file.getName(); final int pos = fileName.lastIndexOf("."); return fileName.substring(0, pos); } + public static String removeExtension(final String fileName) { + // source stackoverflow + final int pos = fileName.lastIndexOf("."); + return fileName.substring(0, pos); + } + private static UUID generateHash(final File file) { UUID hash = null; try { @@ -157,6 +192,13 @@ public JsonObject toJson() { if (subRegionData.isModified()) { obj.add("subregionData", subRegionData.toJson()); } + // Feature.VERSION + if (litematicVersion > -1) { + obj.add("litematicVersion", new JsonPrimitive(litematicVersion)); + } + if (dataVersion > -1) { + obj.add("dataVersion", new JsonPrimitive(dataVersion)); + } return obj; } @@ -171,13 +213,23 @@ public static ServerPlacement fromJson(final JsonObject obj, final Context conte final UUID id = UUID.fromString(obj.get("id").getAsString()); final String name = obj.get("file_name").getAsString(); final UUID hashValue = UUID.fromString(obj.get("hash").getAsString()); + int version = -1; + int dataVersion = -1; PlayerIdentifier owner = PlayerIdentifier.MISSING_PLAYER; if (obj.has("owner")) { owner = context.getPlayerIdentifierProvider().fromJson(obj.get("owner").getAsJsonObject()); } - final ServerPlacement newPlacement = new ServerPlacement(id, name, hashValue, owner); + // Feature.VERSION + if (obj.has("litematicVersion")) { + version = obj.get("litematicVersion").getAsInt(); + } + if (obj.has("dataVersion")) { + dataVersion = obj.get("dataVersion").getAsInt(); + } + + final ServerPlacement newPlacement = new ServerPlacement(id, name, hashValue, owner, version, dataVersion); final ServerPosition pos = ServerPosition.fromJson(obj.get("origin").getAsJsonObject()); if (pos == null) { diff --git a/src/main/java/ch/endte/syncmatica/litematica/LitematicManager.java b/src/main/java/ch/endte/syncmatica/litematica/LitematicManager.java index 2aedd5deb..b58686ab7 100644 --- a/src/main/java/ch/endte/syncmatica/litematica/LitematicManager.java +++ b/src/main/java/ch/endte/syncmatica/litematica/LitematicManager.java @@ -13,6 +13,8 @@ import fi.dy.masa.litematica.data.DataManager; import fi.dy.masa.litematica.data.SchematicHolder; import fi.dy.masa.litematica.schematic.LitematicaSchematic; +import fi.dy.masa.litematica.schematic.SchematicMetadata; +import fi.dy.masa.litematica.schematic.SchematicSchema; import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; import fi.dy.masa.litematica.schematic.placement.SchematicPlacementManager; import fi.dy.masa.litematica.schematic.placement.SubRegionPlacement; @@ -22,7 +24,9 @@ import net.minecraft.util.BlockMirror; import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; +import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.io.File; import java.util.*; @@ -91,8 +95,11 @@ public void renderSyncmatic(final ServerPlacement placement) { final BlockPos origin = placement.getPosition(); - final SchematicPlacement litematicaPlacement = SchematicPlacement.createFor(schematic, origin, file.getName(), true, true); - rendering.put(placement, litematicaPlacement); + final SchematicPlacement litematicaPlacement = SchematicPlacement.createFor(schematic, origin, ServerPlacement.removeExtension(file.getName()), true, true); + // Feature.VERSION + final ServerPlacement adjusted = readVersionInfo(placement, litematicaPlacement); + rendering.put(Objects.requireNonNullElse(adjusted, placement), litematicaPlacement); + ((IIDContainer) litematicaPlacement).syncmatica$setServerId(placement.getId()); if (litematicaPlacement.isLocked()) { litematicaPlacement.toggleLocked(); @@ -103,6 +110,11 @@ public void renderSyncmatic(final ServerPlacement placement) { litematicaPlacement.toggleLocked(); DataManager.getSchematicPlacementManager().addSchematicPlacement(litematicaPlacement, true); + + // Mark as selected if none + if (DataManager.getSchematicPlacementManager().getSelectedSchematicPlacement() == null) { + DataManager.getSchematicPlacementManager().setSelectedSchematicPlacement(litematicaPlacement); + } context.getSyncmaticManager().updateServerPlacement(placement); } @@ -122,6 +134,7 @@ public ServerPlacement syncmaticFromSchematic(final SchematicPlacement schem) { } try { final File placementFile = schem.getSchematicFile(); + if (placementFile == null) { return null; } final FileType fileType = FileType.fromFile(placementFile); if (fileType == FileType.VANILLA_STRUCTURE || fileType == FileType.SCHEMATICA_SCHEMATIC) { ScreenHelper.ifPresent(s -> s.addMessage(Message.MessageType.ERROR, "syncmatica.error.share_incompatible_schematic")); @@ -141,7 +154,10 @@ public ServerPlacement syncmaticFromSchematic(final SchematicPlacement schem) { final String dimension = MinecraftClient.getInstance().getCameraEntity().getEntityWorld().getRegistryKey().getValue().toString(); placement.move(dimension, schem.getOrigin(), schem.getRotation(), schem.getMirror()); transferSubregionDataToServerPlacement(schem, placement); - return placement; + + // Feature.VERSION + final ServerPlacement adjusted = readVersionInfo(placement, schem); + return Objects.requireNonNullElse(adjusted, placement); } catch (final Exception e) { ScreenHelper.ifPresent(s -> s.addMessage(Message.MessageType.ERROR, "syncmatica.error.create_from_schematic", e.getMessage())); } @@ -209,7 +225,14 @@ public void renderSyncmatic(final ServerPlacement placement, final SchematicPlac if (modPlacement.syncmatica$getServerId() != null && !modPlacement.syncmatica$getServerId().equals(placement.getId())) { return; } - rendering.put(placement, litematicaPlacement); + // Feature.VERSION + final ServerPlacement adjusted = readVersionInfo(placement, litematicaPlacement); + if (adjusted != null) { + rendering.put(adjusted, litematicaPlacement); + } + else { + rendering.put(placement, litematicaPlacement); + } modPlacement.syncmatica$setServerId(placement.getId()); if (litematicaPlacement.isLocked()) { @@ -223,6 +246,11 @@ public void renderSyncmatic(final ServerPlacement placement, final SchematicPlac context.getSyncmaticManager().updateServerPlacement(placement); if (addToRendering) { DataManager.getSchematicPlacementManager().addSchematicPlacement(litematicaPlacement, false); + + // Set as selected if none are + if (DataManager.getSchematicPlacementManager().getSelectedSchematicPlacement() == null) { + DataManager.getSchematicPlacementManager().setSelectedSchematicPlacement(litematicaPlacement); + } } } @@ -291,7 +319,13 @@ public void preLoad(final SchematicPlacement schem) { final UUID id = ((IIDContainer) schem).syncmatica$getServerId(); final ServerPlacement p = context.getSyncmaticManager().getPlacement(id); if (isRendered(p)) { - rendering.put(p, schem); + final ServerPlacement adjusted = readVersionInfo(p, schem); + if (adjusted != null) { + rendering.put(adjusted, schem); + } + else { + rendering.put(p, schem); + } DataManager.getSchematicPlacementManager().addSchematicPlacement(schem, false); } } else if (preLoadList != null) { @@ -299,6 +333,28 @@ public void preLoad(final SchematicPlacement schem) { } } + @Nullable + private ServerPlacement readVersionInfo(ServerPlacement p, SchematicPlacement s) { + try { + final File file = s.getSchematicFile(); + if (file != null) { + final File dir = new File(file.getParent()); + + if (file.getName().endsWith(LitematicaSchematic.FILE_EXTENSION)) { + final Pair pair = LitematicaSchematic.readMetadataAndVersionFromFile(dir, file.getName()); + + if (pair != null) { + final SchematicSchema schema = pair.getLeft(); + return p.setVersion(schema.litematicVersion(), schema.minecraftDataVersion()); + } + } + } + } + catch (Exception ignored) {} + + return null; + } + public void commitLoad() { final SyncmaticManager man = context.getSyncmaticManager(); for (final SchematicPlacement schem : preLoadList) { diff --git a/src/main/java/ch/endte/syncmatica/litematica/gui/IGuiBase.java b/src/main/java/ch/endte/syncmatica/litematica/gui/IGuiBase.java new file mode 100644 index 000000000..3dd43a0f6 --- /dev/null +++ b/src/main/java/ch/endte/syncmatica/litematica/gui/IGuiBase.java @@ -0,0 +1,9 @@ +package ch.endte.syncmatica.litematica.gui; + +import fi.dy.masa.malilib.gui.button.ButtonBase; + +import java.util.List; + +public interface IGuiBase { + List getButtons(); +} diff --git a/src/main/java/ch/endte/syncmatica/litematica/gui/WidgetListSyncmaticaServerPlacement.java b/src/main/java/ch/endte/syncmatica/litematica/gui/WidgetListSyncmaticaServerPlacement.java index 29fe36932..894ec6809 100644 --- a/src/main/java/ch/endte/syncmatica/litematica/gui/WidgetListSyncmaticaServerPlacement.java +++ b/src/main/java/ch/endte/syncmatica/litematica/gui/WidgetListSyncmaticaServerPlacement.java @@ -14,6 +14,8 @@ import ch.endte.syncmatica.litematica.ScreenHelper; import ch.endte.syncmatica.util.SyncmaticaUtil; import fi.dy.masa.litematica.gui.Icons; +import fi.dy.masa.litematica.schematic.SchematicSchema; +import fi.dy.masa.litematica.util.DataFixerMode; import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.gui.LeftRight; import fi.dy.masa.malilib.gui.interfaces.ISelectionListener; @@ -116,6 +118,24 @@ private void drawPlacementInfo(final ServerPlacement placement, final DrawContex drawString(drawContext, str, x, y, textColor); y += 12; drawString(drawContext, placement.getLastModifiedBy().getName(), x + 4, y, valueColor); + y += 12; + + // Feature.VERSION + final int litematic = placement.getLitematicVersion(); + final int dataVersion = placement.getDataVersion(); + + if (litematic > -1 && dataVersion > -1) { + final SchematicSchema version = new SchematicSchema(litematic, dataVersion); + final DataFixerMode.Schema schema = DataFixerMode.getSchemaByVersion(dataVersion); + + str = StringUtils.translate("syncmatica.gui.label.placement_info.version", version.litematicVersion()); + drawString(drawContext, str, x, y, textColor); + y += 12; + + str = StringUtils.translate("syncmatica.gui.label.placement_info.schema", schema.getString(), version.minecraftDataVersion()); + drawString(drawContext, str, x, y, textColor); + y += 12; + } } @Override diff --git a/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiBase.java b/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiBase.java index c27c87cc5..0eeb0d705 100644 --- a/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiBase.java +++ b/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiBase.java @@ -1,22 +1,22 @@ package ch.endte.syncmatica.litematica_mixin; +import ch.endte.syncmatica.litematica.gui.IGuiBase; import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.gui.button.ButtonBase; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import java.util.List; @Mixin(GuiBase.class) -public abstract class MixinGuiBase { +public abstract class MixinGuiBase implements IGuiBase { @Final @Shadow(remap = false) private List buttons; - @Unique + @Override public List getButtons() { return buttons; } diff --git a/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiPlacementConfiguration.java b/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiPlacementConfiguration.java index bf5d456d1..93505ed11 100644 --- a/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiPlacementConfiguration.java +++ b/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinGuiPlacementConfiguration.java @@ -8,6 +8,7 @@ import ch.endte.syncmatica.communication.exchange.ModifyExchangeClient; import ch.endte.syncmatica.litematica.LitematicManager; import ch.endte.syncmatica.litematica.ScreenHelper; +import ch.endte.syncmatica.litematica.gui.IGuiBase; import fi.dy.masa.litematica.gui.GuiPlacementConfiguration; import fi.dy.masa.litematica.schematic.placement.SchematicPlacement; import fi.dy.masa.malilib.gui.GuiBase; @@ -35,7 +36,7 @@ public void initGui(final CallbackInfo ci) { if (!LitematicManager.getInstance().isSyncmatic(placement)) { return; } - final List buttons = ((MixinGuiBase) (Object) this).getButtons(); + final List buttons = ((IGuiBase) this).getButtons(); final ButtonBase button = buttons.get(6); // unlock button button.setActionListener((b, k) -> { if (placement.isLocked()) { diff --git a/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinSchematicPlacement.java b/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinSchematicPlacement.java index 5f5efed70..b9c66dc5a 100644 --- a/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinSchematicPlacement.java +++ b/src/main/java/ch/endte/syncmatica/litematica_mixin/MixinSchematicPlacement.java @@ -52,8 +52,8 @@ private static void loadSyncmatic(final JsonObject obj, final CallbackInfoReturn } } - @Inject(method = "(Lfi/dy/masa/litematica/schematic/LitematicaSchematic;Lnet/minecraft/util/math/BlockPos;Ljava/lang/String;ZZ)V", at = @At("TAIL"), remap = false) - public void setNull(final LitematicaSchematic schematic, final BlockPos origin, final String name, final boolean enabled, final boolean enableRender, final CallbackInfo ci) { + @Inject(method = "(Lfi/dy/masa/litematica/schematic/LitematicaSchematic;Lnet/minecraft/util/math/BlockPos;Ljava/lang/String;ZZLfi/dy/masa/litematica/schematic/placement/SchematicPlacementManager;)V", at = @At("TAIL"), remap = false) + public void setNull(LitematicaSchematic schematic, BlockPos origin, String name, boolean enabled, boolean enableRender, SchematicPlacementManager placementManager, CallbackInfo ci) { serverId = null; } diff --git a/src/main/java/ch/endte/syncmatica/network/actor/ActorClientPlayHandler.java b/src/main/java/ch/endte/syncmatica/network/actor/ActorClientPlayHandler.java index 8475f18ba..8b7d4b3a8 100644 --- a/src/main/java/ch/endte/syncmatica/network/actor/ActorClientPlayHandler.java +++ b/src/main/java/ch/endte/syncmatica/network/actor/ActorClientPlayHandler.java @@ -1,7 +1,6 @@ package ch.endte.syncmatica.network.actor; import java.util.Objects; -import ch.endte.syncmatica.Context; import ch.endte.syncmatica.Syncmatica; import ch.endte.syncmatica.communication.ClientCommunicationManager; import ch.endte.syncmatica.communication.CommunicationManager; @@ -52,15 +51,17 @@ public void startEvent(final ClientPlayNetworkHandler handler) public void startClient() { Syncmatica.debug("ActorClientPlayHandler#startClient()"); + /* if (clientPlayNetworkHandler == null) { throw new RuntimeException("Tried to start client before receiving a connection"); } + */ final IFileStorage data = new RedirectFileStorage(); final SyncmaticManager man = new SyncmaticManager(); exTarget = new ExchangeTarget(clientPlayNetworkHandler); final CommunicationManager comms = new ClientCommunicationManager(exTarget); - Context ctx = Syncmatica.initClient(comms, data, man); + Syncmatica.initClient(comms, data, man); clientCommunication = comms; ScreenHelper.init(); LitematicManager.getInstance().setActiveContext(Objects.requireNonNull(getContext(CLIENT_CONTEXT))); diff --git a/src/main/java/ch/endte/syncmatica/network/handler/ClientPlayHandler.java b/src/main/java/ch/endte/syncmatica/network/handler/ClientPlayHandler.java index 20ef1b4b5..6f6589b22 100644 --- a/src/main/java/ch/endte/syncmatica/network/handler/ClientPlayHandler.java +++ b/src/main/java/ch/endte/syncmatica/network/handler/ClientPlayHandler.java @@ -1,7 +1,6 @@ package ch.endte.syncmatica.network.handler; import javax.annotation.Nonnull; -import java.util.Objects; import ch.endte.syncmatica.network.SyncmaticaPacket; import ch.endte.syncmatica.network.actor.ActorClientPlayHandler; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; @@ -17,7 +16,7 @@ */ public class ClientPlayHandler { - public static void decodeSyncData(@Nonnull SyncmaticaPacket data, @Nonnull ClientPlayNetworkHandler handler) + public static void decodeSyncData(@Nonnull SyncmaticaPacket data, ClientPlayNetworkHandler handler) { CallbackInfo ci = new CallbackInfo("receiveSyncPacket", false); ActorClientPlayHandler.getInstance().packetEvent(data.getType(), data.getPacket(), handler, ci); @@ -44,7 +43,12 @@ public static void receiveSyncPayload(@Nonnull SyncmaticaPacket data) public static void receiveSyncPayload(SyncmaticaPacket.Payload payload, ClientPlayNetworking.Context context) { - decodeSyncData(payload.data(), Objects.requireNonNull(context.client().getNetworkHandler())); + // Has threading issues ? + if (context.client().getNetworkHandler() != null) { + decodeSyncData(payload.data(), context.client().getNetworkHandler()); + } else { + decodeSyncData(payload.data(), MinecraftClient.getInstance().getNetworkHandler()); + } } public static void sendSyncPacket(@Nonnull T payload) diff --git a/src/main/resources/assets/syncmatica/lang/en_us.json b/src/main/resources/assets/syncmatica/lang/en_us.json index 1fdf67c67..5577552fa 100644 --- a/src/main/resources/assets/syncmatica/lang/en_us.json +++ b/src/main/resources/assets/syncmatica/lang/en_us.json @@ -14,6 +14,8 @@ "syncmatica.gui.label.placement_info.dimension_id": "Dimension", "syncmatica.gui.label.placement_info.owner": "Originally shared by", "syncmatica.gui.label.placement_info.last_modified": "Last modified by", + "syncmatica.gui.label.placement_info.version": "Litematic Version: §f%d§r", + "syncmatica.gui.label.placement_info.schema": "Minecraft: §f%s§r [Schema §f%d§r]", "syncmatica.error.share_without_shift": "Press shift to share", "syncmatica.error.share_modified_subregions": "Share Error - Connected Server does not support sharing of modified subregions - it needs to update.", "syncmatica.error.modification_deny": "Denied Modification request - Another user is already modifying this placement.", diff --git a/src/main/resources/assets/syncmatica/lang/zh_cn.json b/src/main/resources/assets/syncmatica/lang/zh_cn.json index e16791b82..1e8c80c32 100644 --- a/src/main/resources/assets/syncmatica/lang/zh_cn.json +++ b/src/main/resources/assets/syncmatica/lang/zh_cn.json @@ -1,26 +1,28 @@ { - "syncmatica.gui.button.view_syncmatics": "Syncmatics菜单", - "syncmatica.gui.button.material_gatherings": "材料收集", - "syncmatica.gui.button.load": "载入", - "syncmatica.gui.button.unload": "卸载", - "syncmatica.gui.button.remove": "删除", - "syncmatica.gui.button.download": "下载", - "syncmatica.gui.button.downloading": "下载中...", - "syncmatica.gui.button.share": "上传", - "syncmatica.gui.button.material_gathering_placement": "材料", - "syncmatica.gui.title.manage_server_placements": "管理服务器配置 - %s", - "syncmatica.gui.label.placement_info.file_name": "文件名", - "syncmatica.gui.label.placement_info.position": "原点 (xyz)", - "syncmatica.gui.label.placement_info.dimension_id": "维度", - "syncmatica.gui.label.placement_info.owner": "上传者", - "syncmatica.gui.label.placement_info.last_modified": "最后的修改者", - "syncmatica.error.share_without_shift": "按下Shift键以分享原理图", - "syncmatica.error.share_modified_subregions": "共享错误:服务器不支持共享已修改的子区域,它需要更新。", - "syncmatica.error.modification_deny": "被拒绝的修改请求 - 其他用户已修改此文件的展示位置。", - "syncmatica.error.player_dimension_mismatch": "玩家需要与要加载的原理图处于同一维度。", - "syncmatica.error.create_from_schematic": "从原理图创建同步时出错: {} 。", - "syncmatica.error.share_incompatible_schematic": "请使用主菜单中的原理图管理器转换此文件以共享。", - "syncmatica.error.invalid_file": "无法共享此类型的文件。", - "syncmatica.error.failed_to_load": "无法加载Litematica模组 {} 。", - "syncmatica.success.modification_accepted": "允许的修改请求 - 请再次锁定展示位置以更新。" -} + "syncmatica.gui.button.view_syncmatics": "Syncmatics菜单", + "syncmatica.gui.button.material_gatherings": "材料收集", + "syncmatica.gui.button.load": "载入", + "syncmatica.gui.button.unload": "卸载", + "syncmatica.gui.button.remove": "删除", + "syncmatica.gui.button.download": "下载", + "syncmatica.gui.button.downloading": "下载中...", + "syncmatica.gui.button.share": "上传", + "syncmatica.gui.button.material_gathering_placement": "材料", + "syncmatica.gui.title.manage_server_placements": "管理服务器配置 - %s", + "syncmatica.gui.label.placement_info.file_name": "文件名", + "syncmatica.gui.label.placement_info.position": "原点 (xyz)", + "syncmatica.gui.label.placement_info.dimension_id": "维度", + "syncmatica.gui.label.placement_info.owner": "上传者", + "syncmatica.gui.label.placement_info.last_modified": "最后的修改者", + "syncmatica.gui.label.placement_info.version": "精简版: §f%d§r", + "syncmatica.gui.label.placement_info.schema": "我的世界: §f%s§r [架构 §f%d§r]", + "syncmatica.error.share_without_shift": "按下Shift键以分享原理图", + "syncmatica.error.share_modified_subregions": "共享错误:服务器不支持共享已修改的子区域,它需要更新。", + "syncmatica.error.modification_deny": "被拒绝的修改请求 - 其他用户已修改此文件的展示位置。", + "syncmatica.error.player_dimension_mismatch": "玩家需要与要加载的原理图处于同一维度。", + "syncmatica.error.create_from_schematic": "从原理图创建同步时出错: {} 。", + "syncmatica.error.share_incompatible_schematic": "请使用主菜单中的原理图管理器转换此文件以共享。", + "syncmatica.error.invalid_file": "无法共享此类型的文件。", + "syncmatica.error.failed_to_load": "无法加载Litematica模组 {} 。", + "syncmatica.success.modification_accepted": "允许的修改请求 - 请再次锁定展示位置以更新。" +} \ No newline at end of file diff --git a/src/main/resources/assets/syncmatica/lang/zh_tw.json b/src/main/resources/assets/syncmatica/lang/zh_tw.json index db25b17b0..e5f4f9af4 100644 --- a/src/main/resources/assets/syncmatica/lang/zh_tw.json +++ b/src/main/resources/assets/syncmatica/lang/zh_tw.json @@ -1,26 +1,28 @@ { - "syncmatica.gui.button.view_syncmatics": "Syncmatics 選單", - "syncmatica.gui.button.material_gatherings": "材料收集", - "syncmatica.gui.button.load": "載入", - "syncmatica.gui.button.unload": "卸載", - "syncmatica.gui.button.remove": "刪除", - "syncmatica.gui.button.download": "下載", - "syncmatica.gui.button.downloading": "下載中...", - "syncmatica.gui.button.share": "分享", - "syncmatica.gui.button.material_gathering_placement": "材料", - "syncmatica.gui.title.manage_server_placements": "管理伺服器配置 - %s", - "syncmatica.gui.label.placement_info.file_name": "檔案名稱", - "syncmatica.gui.label.placement_info.position": "原點 (xyz)", - "syncmatica.gui.label.placement_info.dimension_id": "維度", - "syncmatica.gui.label.placement_info.owner": "上傳者", - "syncmatica.gui.label.placement_info.last_modified": "最後修改", - "syncmatica.error.share_without_shift": "按下 Shift 鍵以分享原理圖", - "syncmatica.error.share_modified_subregions": "分享錯誤:伺服器不支持共享已修改的子區域,需要更新。", - "syncmatica.error.modification_deny": "修改請求被拒絕 - 其他用戶已修改此檔案的展示位置。", - "syncmatica.error.player_dimension_mismatch": "玩家需要與要載入的原理圖處於同一維度。", - "syncmatica.error.create_from_schematic": "從原理圖建立同步時出錯: {} 。", - "syncmatica.error.share_incompatible_schematic": "請使用主選單中的原理圖管理員轉換此檔案以分享。", - "syncmatica.error.invalid_file": "無法分享此類型的檔案。", - "syncmatica.error.failed_to_load": "無法載入 Litematica 模組 {} 。", - "syncmatica.success.modification_accepted": "修改請求已允許 - 請再次鎖定展示位置以更新。" -} + "syncmatica.gui.button.view_syncmatics": "Syncmatics 選單", + "syncmatica.gui.button.material_gatherings": "材料收集", + "syncmatica.gui.button.load": "載入", + "syncmatica.gui.button.unload": "卸載", + "syncmatica.gui.button.remove": "刪除", + "syncmatica.gui.button.download": "下載", + "syncmatica.gui.button.downloading": "下載中...", + "syncmatica.gui.button.share": "分享", + "syncmatica.gui.button.material_gathering_placement": "材料", + "syncmatica.gui.title.manage_server_placements": "管理伺服器配置 - %s", + "syncmatica.gui.label.placement_info.file_name": "檔案名稱", + "syncmatica.gui.label.placement_info.position": "原點 (xyz)", + "syncmatica.gui.label.placement_info.dimension_id": "維度", + "syncmatica.gui.label.placement_info.owner": "上傳者", + "syncmatica.gui.label.placement_info.last_modified": "最後修改", + "syncmatica.gui.label.placement_info.version": "精簡版: §f%d§r", + "syncmatica.gui.label.placement_info.schema": "我的世界: §f%s§r [架构 §f%d§r]", + "syncmatica.error.share_without_shift": "按下 Shift 鍵以分享原理圖", + "syncmatica.error.share_modified_subregions": "分享錯誤:伺服器不支持共享已修改的子區域,需要更新。", + "syncmatica.error.modification_deny": "修改請求被拒絕 - 其他用戶已修改此檔案的展示位置。", + "syncmatica.error.player_dimension_mismatch": "玩家需要與要載入的原理圖處於同一維度。", + "syncmatica.error.create_from_schematic": "從原理圖建立同步時出錯: {} 。", + "syncmatica.error.share_incompatible_schematic": "請使用主選單中的原理圖管理員轉換此檔案以分享。", + "syncmatica.error.invalid_file": "無法分享此類型的檔案。", + "syncmatica.error.failed_to_load": "無法載入 Litematica 模組 {} 。", + "syncmatica.success.modification_accepted": "修改請求已允許 - 請再次鎖定展示位置以更新。" +} \ No newline at end of file diff --git a/src/main/resources/syncmatica.litematica_mixin.json b/src/main/resources/syncmatica.litematica_mixin.json index 64a02a532..e0a935ddf 100644 --- a/src/main/resources/syncmatica.litematica_mixin.json +++ b/src/main/resources/syncmatica.litematica_mixin.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "ch.endte.syncmatica.litematica_mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_21", "mixins": [], "client": [ "MixinGuiMainMenu", diff --git a/src/main/resources/syncmatica.mixin.json b/src/main/resources/syncmatica.mixin.json index b649e0b2f..1c6c64f13 100644 --- a/src/main/resources/syncmatica.mixin.json +++ b/src/main/resources/syncmatica.mixin.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "ch.endte.syncmatica.mixin", - "compatibilityLevel": "JAVA_8", + "compatibilityLevel": "JAVA_21", "mixins": [ "MixinMinecraftServer", "MixinPlayerManager",