Skip to content

Commit

Permalink
block entities servux paste (#3)
Browse files Browse the repository at this point in the history
* feat: paste to servux

* feat: paste to servux

* feat: paste to servux

* fix
  • Loading branch information
zly2006 authored Jun 29, 2024
1 parent e2ba05e commit 6c82dee
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
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

0 comments on commit 6c82dee

Please sign in to comment.