From 070f2fc2a3cc220b1fc3ea93ffefb037919432e0 Mon Sep 17 00:00:00 2001 From: Liyan Zhao Date: Fri, 28 Jun 2024 22:18:55 +0800 Subject: [PATCH 1/4] feat: paste to servux --- .../schematic/LitematicaSchematic.java | 4 +-- .../placement/SchematicPlacement.java | 27 +++++++++++++++++++ .../placement/SchematicPlacementManager.java | 22 +++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java b/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java index 7fc1c4330f..5092ad8356 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java @@ -60,7 +60,7 @@ public class LitematicaSchematic public static final int SCHEMATIC_VERSION_1_13_2 = 5; public static final int MINECRAFT_DATA_VERSION_1_12 = 1139; // MC 1.12 public static final int MINECRAFT_DATA_VERSION_1_13_2 = 1631; // MC 1.13.2 - public static final int MINECRAFT_DATA_VERSION = SharedConstants.getGameVersion().getSaveVersion().getId(); + public static final int MINECRAFT_DATA_VERSION = SharedConstants.getGameVersion().getSaveVersion().getId(); public static final int SCHEMATIC_VERSION = 7; // This is basically a "sub-version" for the schematic version, // intended to help with possible data fix needs that are discovered. @@ -992,7 +992,7 @@ public Map> getScheduledFluidTicksForRegion(String return this.pendingFluidTicks.get(regionName); } - private NbtCompound writeToNBT() + public NbtCompound writeToNBT() { NbtCompound nbt = new NbtCompound(); diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java index 7d48a60939..c8d846590d 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java @@ -12,6 +12,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtHelper; import org.apache.commons.lang3.tuple.Pair; import net.minecraft.structure.StructurePlacementData; @@ -1050,4 +1052,29 @@ private static int getNextBoxColor() return color; } + + public NbtCompound toNbt(boolean withSchematic) + { + NbtCompound compound = new NbtCompound(); + compound.putString("Name", name); + if (withSchematic) + { + compound.put("Schematics", schematic.writeToNBT()); + } + compound.put("Origin", NbtHelper.fromBlockPos(origin)); + compound.putInt("Rotation", rotation.ordinal()); + compound.putInt("Mirror", mirror.ordinal()); + NbtCompound subs = new NbtCompound(); + for (String name : relativeSubRegionPlacements.keySet()) { + NbtCompound compound1 = new NbtCompound(); + SubRegionPlacement subRegionPlacement = relativeSubRegionPlacements.get(name); + subs.put(name, compound1); + + compound.put("Pos", NbtHelper.fromBlockPos(subRegionPlacement.getPos())); + compound.putInt("Rotation", subRegionPlacement.getRotation().ordinal()); + compound.putInt("Mirror", subRegionPlacement.getMirror().ordinal()); + } + compound.put("SubRegions", subs); + return compound; + } } diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java index 8a74fa3027..dd517af184 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java @@ -15,6 +15,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import fi.dy.masa.litematica.Litematica; +import fi.dy.masa.litematica.data.EntitiesDataStorage; +import fi.dy.masa.litematica.network.ServuxLitematicaHandler; +import fi.dy.masa.litematica.network.ServuxLitematicaPacket; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -806,12 +810,20 @@ public void pastePlacementToWorld(final SchematicPlacement schematicPlacement, b } else if(mc.isIntegratedServerRunning() == false || Configs.Generic.PASTE_USING_COMMANDS_IN_SP.getBooleanValue()) { - TaskPasteSchematicPerChunkBase task = new TaskPasteSchematicPerChunkCommand(Collections.singletonList(schematicPlacement), range, changedBlocksOnly); - TaskScheduler.getInstanceClient().scheduleTask(task, Configs.Generic.COMMAND_TASK_INTERVAL.getIntegerValue()); - - if (printMessage) + if (EntitiesDataStorage.getInstance().hasServuxServer()) { - InfoUtils.showGuiOrActionBarMessage(MessageType.INFO, "litematica.message.scheduled_task_added"); + Litematica.logger.warn("Found servux server, I am sending NBT to it."); + ServuxLitematicaHandler.getInstance().encodeClientData(ServuxLitematicaPacket.ResponseC2SStart(schematicPlacement.toNbt(true))); + } + else + { + TaskPasteSchematicPerChunkBase task = new TaskPasteSchematicPerChunkCommand(Collections.singletonList(schematicPlacement), range, changedBlocksOnly); + TaskScheduler.getInstanceClient().scheduleTask(task, Configs.Generic.COMMAND_TASK_INTERVAL.getIntegerValue()); + + if (printMessage) + { + InfoUtils.showGuiOrActionBarMessage(MessageType.INFO, "litematica.message.scheduled_task_added"); + } } } else if (mc.isIntegratedServerRunning()) From 79611f144f83d60bd7f017b7b89b7da48589d7a3 Mon Sep 17 00:00:00 2001 From: Liyan Zhao Date: Fri, 28 Jun 2024 22:27:18 +0800 Subject: [PATCH 2/4] feat: paste to servux --- .../schematic/placement/SchematicPlacementManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java index dd517af184..9c8822f8fc 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacementManager.java @@ -25,6 +25,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.nbt.NbtCompound; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; @@ -813,7 +814,9 @@ else if(mc.isIntegratedServerRunning() == false || Configs.Generic.PASTE_USING_C if (EntitiesDataStorage.getInstance().hasServuxServer()) { Litematica.logger.warn("Found servux server, I am sending NBT to it."); - ServuxLitematicaHandler.getInstance().encodeClientData(ServuxLitematicaPacket.ResponseC2SStart(schematicPlacement.toNbt(true))); + NbtCompound nbt = schematicPlacement.toNbt(true); + nbt.putString("Task", "LitematicaPaste"); + ServuxLitematicaHandler.getInstance().encodeClientData(ServuxLitematicaPacket.ResponseC2SStart(nbt)); } else { From cc09a073c27299b73c37a4a3b15621fe0a34a532 Mon Sep 17 00:00:00 2001 From: Liyan Zhao Date: Fri, 28 Jun 2024 22:39:48 +0800 Subject: [PATCH 3/4] feat: paste to servux --- .../schematic/placement/SchematicPlacement.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java index c8d846590d..2ee9457d61 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java @@ -1066,13 +1066,13 @@ public NbtCompound toNbt(boolean withSchematic) compound.putInt("Mirror", mirror.ordinal()); NbtCompound subs = new NbtCompound(); for (String name : relativeSubRegionPlacements.keySet()) { - NbtCompound compound1 = new NbtCompound(); + NbtCompound sub = new NbtCompound(); SubRegionPlacement subRegionPlacement = relativeSubRegionPlacements.get(name); - subs.put(name, compound1); + subs.put(name, sub); - compound.put("Pos", NbtHelper.fromBlockPos(subRegionPlacement.getPos())); - compound.putInt("Rotation", subRegionPlacement.getRotation().ordinal()); - compound.putInt("Mirror", subRegionPlacement.getMirror().ordinal()); + sub.put("Pos", NbtHelper.fromBlockPos(subRegionPlacement.getPos())); + sub.putInt("Rotation", subRegionPlacement.getRotation().ordinal()); + sub.putInt("Mirror", subRegionPlacement.getMirror().ordinal()); } compound.put("SubRegions", subs); return compound; From 2916897debfbdc8335aaaa42ef2752308614a1c2 Mon Sep 17 00:00:00 2001 From: Liyan Zhao Date: Fri, 28 Jun 2024 23:04:33 +0800 Subject: [PATCH 4/4] fix --- .../masa/litematica/schematic/placement/SchematicPlacement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java index 2ee9457d61..47ede0add7 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/placement/SchematicPlacement.java @@ -1073,6 +1073,7 @@ public NbtCompound toNbt(boolean withSchematic) sub.put("Pos", NbtHelper.fromBlockPos(subRegionPlacement.getPos())); sub.putInt("Rotation", subRegionPlacement.getRotation().ordinal()); sub.putInt("Mirror", subRegionPlacement.getMirror().ordinal()); + sub.putString("Name", subRegionPlacement.getName()); } compound.put("SubRegions", subs); return compound;