Skip to content
Draft
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
1 change: 1 addition & 0 deletions core/src/main/java/com/volmit/iris/core/IrisSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public static class IrisSettingsGenerator {
public boolean preventLeafDecay = true;
public boolean useMulticore = false;
public boolean offsetNoiseTypes = false;
public boolean useShrinkWrapFix = false;
public boolean earlyCustomBlocks = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.volmit.iris.core.commands;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand All @@ -31,6 +32,7 @@
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IrisDimension;
import com.volmit.iris.engine.object.IrisJigsawPiece;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.context.IrisContext;
Expand All @@ -45,18 +47,25 @@
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.io.CountingDataInputStream;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.mantle.TectonicPlate;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.nbt.mca.MCAFile;
import com.volmit.iris.util.nbt.mca.MCAUtil;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.SneakyThrows;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import net.jpountz.lz4.LZ4FrameInputStream;
import net.jpountz.lz4.LZ4FrameOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOCase;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.lang.RandomStringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
Expand All @@ -67,10 +76,13 @@
import java.net.NetworkInterface;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand All @@ -92,6 +104,52 @@ public void Sentry() {
Iris.reportError(new Exception("This is a test"));
}

@Decree(description = "Dev cmd to fix all the broken objects caused by faulty shrinkwarp")
public void unfuckAllObjects(
@Param(aliases = "dimension", description = "The dimension type to create the world with", defaultValue = "null")
IrisDimension type
) {
if (type == null) {
sender().sendMessage("Type cant be null?");
return;
}
var ps = PrecisionStopwatch.start();
IrisData dm = IrisData.get(Iris.instance.getDataFolder("packs", type.getLoadKey()));

ConcurrentHashMap<String, IrisJigsawPiece> cache = new ConcurrentHashMap<>();
dm.getJigsawPieceLoader().streamAll().parallel().forEach(irisJigsawPiece -> {
try {
cache.put(dm.getObjectLoader().load(irisJigsawPiece.getObject()).getLoadFile().getPath(), irisJigsawPiece);
} catch (Exception e) {
e.printStackTrace();
}
});

AtomicInteger size = new AtomicInteger(dm.getObjectLoader().getPossibleKeys().length);
sender().sendMessage("Found " + size + " objects in " + type.getFolderName());
var gson = new Gson();
dm.getObjectLoader().streamAll().parallel().forEach(o -> {
try {
o.shrinkwrap();
if (cache.containsKey(o.getLoadFile().getPath())) {
var piece = cache.get(o.getLoadFile().getPath());
piece.getConnectors().forEach(connector -> connector.setPosition(o.applyRecentering(connector.getPosition())));
IO.writeAll(piece.getLoadFile(), new JSONObject(gson.toJson(piece)).toString(4));
}
o.write(o.getLoadFile());
size.getAndDecrement();
Iris.debug("Processed: " + o.getLoadKey() + ", Left: " + size.get());
} catch (Exception e) {
Iris.info("Failed to process: " + o.getLoadKey());
e.printStackTrace();
}

});
ps.end();
sender().sendMessage("Took: " + Form.duration(ps.getMillis()));
sender().sendMessage(size + " Failed");
}

@Decree(description = "Test")
public void mantle(@Param(defaultValue = "false") boolean plate, @Param(defaultValue = "21474836474") String name) throws Throwable {
var base = Iris.instance.getDataFile("dump", "pv." + name + ".ttp.lz4b.bin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public JigsawEditor(Player player, IrisJigsawPiece piece, IrisObject object, Fil
editors.get(player).close();
}

editors.put(player, this);
if (object == null) {
throw new RuntimeException("Object is null! " + piece.getObject());
}
editors.put(player, this);
this.object = object;
this.player = player;
origin = player.getLocation().clone().add(0, 7, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void open(VolmitSender sender, long seed, Consumer<World> onDone) throws
sender.sendMessage("Can't find dimension: " + getName());
return;
} else if (sender.isPlayer()) {
sender.player().setGameMode(GameMode.SPECTATOR);
J.s(() -> sender.player().setGameMode(GameMode.SPECTATOR));
}

try {
Expand Down
107 changes: 64 additions & 43 deletions core/src/main/java/com/volmit/iris/core/tools/IrisConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@

import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.*;
import com.volmit.iris.util.data.Varint;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.io.NamedTag;
import com.volmit.iris.util.nbt.tag.*;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.reflect.V;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.FileUtil;
import org.bukkit.util.Vector;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import java.io.*;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -39,31 +31,38 @@ public static void convertSchematics(VolmitSender sender) {
sender.sendMessage("No schematic files to convert found in " + folder.getAbsolutePath());
return;
}

AtomicInteger counter = new AtomicInteger(0);
var stopwatch = PrecisionStopwatch.start();
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(() -> {
for (File schem : fileList) {
try {
for (File schem : fileList) {
try {
PrecisionStopwatch p = PrecisionStopwatch.start();
IrisObject object = null;
boolean largeObject = false;
NamedTag tag = null;
NamedTag tag;
try {
tag = NBTUtil.read(schem);
} catch (IOException e) {
Iris.info(C.RED + "Failed to read: " + schem.getName());
throw new RuntimeException(e);
}
CompoundTag compound = (CompoundTag) tag.getTag();
int version = resolveVersion(compound);
if (!(version == 2 || version == 3))
throw new RuntimeException(C.RED + "Unsupported schematic version: " + version);

if (compound.containsKey("Palette") && compound.containsKey("Width") && compound.containsKey("Height") && compound.containsKey("Length")) {
compound = version == 3 ? (CompoundTag) compound.get("Schematic") : compound;
int objW = ((ShortTag) compound.get("Width")).getValue();
int objH = ((ShortTag) compound.get("Height")).getValue();
int objD = ((ShortTag) compound.get("Length")).getValue();
int i = -1;
int mv = objW * objH * objD;
AtomicInteger v = new AtomicInteger(0);
if (mv > 500_000) {
if (mv > 2_000_000) {
largeObject = true;
Iris.info(C.GRAY + "Converting.. "+ schem.getName() + " -> " + schem.getName().replace(".schem", ".iob"));
Iris.info(C.GRAY + "Converting.. " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob"));
Iris.info(C.GRAY + "- It may take a while");
if (sender.isPlayer()) {
i = J.ar(() -> {
Expand All @@ -72,6 +71,7 @@ public static void convertSchematics(VolmitSender sender) {
}
}

compound = version == 3 ? (CompoundTag) compound.get("Blocks") : compound;
CompoundTag paletteTag = (CompoundTag) compound.get("Palette");
Map<Integer, BlockData> blockmap = new HashMap<>(paletteTag.size(), 0.9f);
for (Map.Entry<String, Tag<?>> entry : paletteTag.getValue().entrySet()) {
Expand All @@ -82,56 +82,77 @@ public static void convertSchematics(VolmitSender sender) {
blockmap.put(blockId, bd);
}

ByteArrayTag byteArray = (ByteArrayTag) compound.get("BlockData");
boolean isBytes = version == 3 ? compound.getByteArrayTag("Data").length() < 128 : ((IntTag) compound.get("PaletteMax")).getValue() < 128;
ByteArrayTag byteArray = version == 3 ? (ByteArrayTag) compound.get("Data") : (ByteArrayTag) compound.get("BlockData");
byte[] originalBlockArray = byteArray.getValue();

IrisObject object = new IrisObject(objW, objH, objD);
var din = new DataInputStream(new ByteArrayInputStream(originalBlockArray));
object = new IrisObject(objW, objH, objD);
for (int h = 0; h < objH; h++) {
for (int d = 0; d < objD; d++) {
for (int w = 0; w < objW; w++) {
BlockData bd = blockmap.get(Byte.toUnsignedInt(originalBlockArray[v.get()]));
int blockIndex = isBytes ? din.read() & 0xFF : Varint.readUnsignedVarInt(din);
BlockData bd = blockmap.get(blockIndex);
if (!bd.getMaterial().isAir()) {
object.setUnsigned(w, h, d, bd);
}
v.getAndAdd(1);
}
}
}

if (i != -1) J.car(i);
try {
object.shrinkwrap();
object.write(new File(folder, schem.getName().replace(".schem", ".iob")));
} catch (IOException e) {
Iris.info(C.RED + "Failed to save: " + schem.getName());
throw new RuntimeException(e);
}
if (sender.isPlayer()) {
counter.incrementAndGet();
if (sender.isPlayer()) {
if (largeObject) {
sender.sendMessage(C.IRIS + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob") + " in " + Form.duration(p.getMillis()));
} else {
sender.sendMessage(C.IRIS + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob"));
}
}
if (largeObject) {
sender.sendMessage(C.IRIS + "Converted "+ schem.getName() + " -> " + schem.getName().replace(".schem", ".iob") + " in " + Form.duration(p.getMillis()));
Iris.info(C.GRAY + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob") + " in " + Form.duration(p.getMillis()));
} else {
sender.sendMessage(C.IRIS + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob"));
Iris.info(C.GRAY + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob"));
}
FileUtils.delete(schem);
} catch (IOException e) {
sender.sendMessage(C.RED + "Failed to save: " + schem.getName());
throw new IOException(e);
}
if (largeObject) {
Iris.info(C.GRAY + "Converted "+ schem.getName() + " -> " + schem.getName().replace(".schem", ".iob") + " in " + Form.duration(p.getMillis()));
} else {
Iris.info(C.GRAY + "Converted " + schem.getName() + " -> " + schem.getName().replace(".schem", ".iob"));
}
FileUtils.delete(schem);
}
} catch (Exception e) {
Iris.info(C.RED + "Failed to convert: " + schem.getName());
if (sender.isPlayer()) {


} catch (Exception e) {
sender.sendMessage(C.RED + "Failed to convert: " + schem.getName());
e.printStackTrace();
}
e.printStackTrace();
Iris.reportError(e);
}
}
sender.sendMessage(C.GRAY + "converted: " + fileList.length);
stopwatch.end();
if (counter.get() != 0) {
sender.sendMessage(C.GRAY + "converted: " + counter.get() + " in " + Form.duration(stopwatch.getMillis()));
}
if (counter.get() < fileList.length) {
sender.sendMessage(C.RED + "Some schematics failed to convert. Check the console for details.");
}
});
}

private static int resolveVersion(CompoundTag compound) throws Exception {
try {

IntTag root = compound.getIntTag("Version");
if (root != null) {
return root.getValue();
}
CompoundTag schematic = (CompoundTag) compound.get("Schematic");
return schematic.getIntTag("Version").getValue();
} catch (NullPointerException e) {
throw new Exception("Cannot resolve schematic version", e);
}
}

}


Expand Down
Loading