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..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 @@ -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,30 @@ 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 sub = new NbtCompound(); + SubRegionPlacement subRegionPlacement = relativeSubRegionPlacements.get(name); + subs.put(name, sub); + + 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; + } } 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..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 @@ -15,12 +15,17 @@ 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; 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; @@ -806,12 +811,22 @@ 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."); + NbtCompound nbt = schematicPlacement.toNbt(true); + nbt.putString("Task", "LitematicaPaste"); + ServuxLitematicaHandler.getInstance().encodeClientData(ServuxLitematicaPacket.ResponseC2SStart(nbt)); + } + 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())