mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
create SpongeSchematicAddon
This commit is contained in:
1 parent
b8a841f88e
commit
cc660e820d
3 files changed
+143
No files matched your search
@@ -4,8 +4,13 @@ plugins {
|
|||||||
id("com.github.johnrengelman.shadow")
|
id("com.github.johnrengelman.shadow")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("https://jitpack.io/") }
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
"shadedApi"("commons-io:commons-io:2.6")
|
"shadedApi"("commons-io:commons-io:2.6")
|
||||||
|
"shadedApi"("com.github.Querz:NBT:6.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named<ShadowJar>("shadowJar") {
|
tasks.named<ShadowJar>("shadowJar") {
|
||||||
|
|||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
package com.dfsek.terra.addons.sponge;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
|
|
||||||
|
import net.querz.nbt.io.NBTDeserializer;
|
||||||
|
import net.querz.nbt.io.NBTUtil;
|
||||||
|
import net.querz.nbt.tag.ByteArrayTag;
|
||||||
|
import net.querz.nbt.tag.CompoundTag;
|
||||||
|
import net.querz.nbt.tag.IntTag;
|
||||||
|
import net.querz.nbt.tag.Tag;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.PushbackInputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.Platform;
|
||||||
|
import com.dfsek.terra.api.addon.TerraAddon;
|
||||||
|
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||||
|
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||||
|
import com.dfsek.terra.api.inject.annotations.Inject;
|
||||||
|
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||||
|
import com.dfsek.terra.api.structure.Structure;
|
||||||
|
|
||||||
|
|
||||||
|
public class SpongeSchematicAddon extends TerraAddon {
|
||||||
|
@Inject
|
||||||
|
private Platform platform;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
platform.getEventManager()
|
||||||
|
.getHandler(FunctionalEventHandler.class)
|
||||||
|
.register(this, ConfigPackPreLoadEvent.class)
|
||||||
|
.then(event -> {
|
||||||
|
CheckedRegistry<Structure> structureRegistry = event.getPack().getOrCreateRegistry(Structure.class);
|
||||||
|
event.getPack().getLoader().open("", ".schem").thenEntries(entries -> {
|
||||||
|
for(Map.Entry<String, InputStream> entry : entries) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}).close();
|
||||||
|
})
|
||||||
|
.failThrough();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String convert(InputStream in) {
|
||||||
|
try {
|
||||||
|
CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag();
|
||||||
|
int wid = baseTag.getShort("Width");
|
||||||
|
int len = baseTag.getShort("Length");
|
||||||
|
int hei = baseTag.getShort("Height");
|
||||||
|
|
||||||
|
ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData");
|
||||||
|
|
||||||
|
CompoundTag palette = (CompoundTag) baseTag.get("Palette");
|
||||||
|
Map<Integer, String> data = new HashMap<>();
|
||||||
|
|
||||||
|
for(Map.Entry<String, Tag<?>> entry : palette.entrySet()) {
|
||||||
|
data.put(((IntTag) entry.getValue()).asInt(), entry.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] arr = blocks.getValue();
|
||||||
|
ScriptBuilder builder = new ScriptBuilder();
|
||||||
|
for(int x = 0; x < hei; x++) {
|
||||||
|
for(int y = 0; y < wid; y++) {
|
||||||
|
for(int z = 0; z < len; z++) {
|
||||||
|
String block = data.get((int) arr[x+z*wid+y*wid*len]);
|
||||||
|
if(block.startsWith("minecraft:structure_void")) continue;
|
||||||
|
builder.block(x, y, z, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
private static InputStream detectDecompression(InputStream is) throws IOException {
|
||||||
|
PushbackInputStream pbis = new PushbackInputStream(is, 2);
|
||||||
|
int signature = (pbis.read() & 0xFF) + (pbis.read() << 8);
|
||||||
|
pbis.unread(signature >> 8);
|
||||||
|
pbis.unread(signature & 0xFF);
|
||||||
|
if (signature == GZIPInputStream.GZIP_MAGIC) {
|
||||||
|
return new GZIPInputStream(pbis);
|
||||||
|
}
|
||||||
|
return pbis;
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package com.dfsek.terra.addons.sponge;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
|
import com.dfsek.terra.api.structure.Structure;
|
||||||
|
import com.dfsek.terra.api.structure.buffer.Buffer;
|
||||||
|
import com.dfsek.terra.api.structure.buffer.BufferedItem;
|
||||||
|
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||||
|
import com.dfsek.terra.api.util.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.world.Chunk;
|
||||||
|
import com.dfsek.terra.api.world.World;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
||||||
|
public class SpongeStructure implements Structure {
|
||||||
|
|
||||||
|
private final BufferedItem[][][] blocks;
|
||||||
|
|
||||||
|
public SpongeStructure() {
|
||||||
|
blocks = new BufferedItem[0][][];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(Vector3 location, World world, Chunk chunk, Random random, Rotation rotation) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean generate(Vector3 location, World world, Random random, Rotation rotation) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getID() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user