Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block entities servux paste #3

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -992,7 +992,7 @@ public Map<BlockPos, OrderedTick<Fluid>> getScheduledFluidTicksForRegion(String
return this.pendingFluidTicks.get(regionName);
}

private NbtCompound writeToNBT()
public NbtCompound writeToNBT()
{
NbtCompound nbt = new NbtCompound();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Loading