Update create_datapack (#1227)
This commit is contained in:
1 parent
b46a4d9668
commit
1485e8978b
2 files changed
+83
-2
No files matched your search
@@ -29,6 +29,7 @@ import carpet.script.utils.WorldTools;
|
||||
import carpet.script.value.BooleanValue;
|
||||
import carpet.script.value.EntityValue;
|
||||
import carpet.script.value.FormattedTextValue;
|
||||
import carpet.script.value.LazyListValue;
|
||||
import carpet.script.value.ListValue;
|
||||
import carpet.script.value.MapValue;
|
||||
import carpet.script.value.NBTSerializableValue;
|
||||
@@ -50,6 +51,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtHelper;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.NbtString;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
@@ -1180,6 +1182,75 @@ public class Auxiliary {
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void zipValueToText(Path path, Value output) throws IOException
|
||||
{
|
||||
List<Value> toJoin;
|
||||
String string;
|
||||
String delimiter=System.lineSeparator();
|
||||
// i dont know it shoule be \n or System.lineSeparator
|
||||
if (output instanceof LazyListValue)
|
||||
{
|
||||
toJoin = ((LazyListValue) output).unroll();
|
||||
string = toJoin.stream().map(Value::getString).collect(Collectors.joining(delimiter));
|
||||
}
|
||||
else if (output instanceof ListValue)
|
||||
{
|
||||
toJoin = ((ListValue) output).getItems();
|
||||
string = toJoin.stream().map(Value::getString).collect(Collectors.joining(delimiter));
|
||||
}
|
||||
else
|
||||
{
|
||||
string = output.getString();
|
||||
}
|
||||
|
||||
|
||||
Files.createDirectories(path.getParent());
|
||||
BufferedWriter bufferedWriter = Files.newBufferedWriter(path);
|
||||
Throwable incident = null;
|
||||
try
|
||||
{
|
||||
bufferedWriter.write(string);
|
||||
}
|
||||
catch (Throwable shitHappened)
|
||||
{
|
||||
incident = shitHappened;
|
||||
throw shitHappened;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (incident != null) {
|
||||
try {
|
||||
bufferedWriter.close();
|
||||
} catch (Throwable otherShitHappened) {
|
||||
incident.addSuppressed(otherShitHappened);
|
||||
}
|
||||
} else {
|
||||
bufferedWriter.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void zipValueToNBT(Path path, Value output) throws IOException
|
||||
{
|
||||
|
||||
|
||||
NBTSerializableValue tagValue = (output instanceof NBTSerializableValue)
|
||||
? (NBTSerializableValue) output
|
||||
: new NBTSerializableValue(output.getString());
|
||||
NbtElement tag = tagValue.getTag();
|
||||
Files.createDirectories(path.getParent());
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (tag instanceof NbtCompound)
|
||||
NbtIo.writeCompressed((NbtCompound) tag, Files.newOutputStream(path));
|
||||
}
|
||||
catch (Throwable shitHappened)
|
||||
{
|
||||
throw shitHappened;
|
||||
}
|
||||
}
|
||||
|
||||
private static void walkTheDPMap(MapValue node, Path path) throws IOException
|
||||
{
|
||||
@@ -1193,7 +1264,13 @@ public class Auxiliary {
|
||||
{
|
||||
zipValueToJson(child, val);
|
||||
}
|
||||
else
|
||||
else if (strkey.endsWith(".mcfunction")|strkey.endsWith(".txt")|strkey.endsWith(".mcmeta"))
|
||||
{
|
||||
zipValueToText(child, val);
|
||||
}else if (strkey.endsWith(".nbt"))
|
||||
{
|
||||
zipValueToNBT(child, val);
|
||||
}else
|
||||
{
|
||||
if (!(val instanceof MapValue)) throw new InternalExpressionException("Value of "+strkey+" should be a map");
|
||||
Files.createDirectory(child);
|
||||
|
||||
Reference in new issue
Block a user