mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
format
This commit is contained in:
@@ -1,21 +1,5 @@
|
||||
package com.dfsek.terra.addons.sponge;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
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;
|
||||
|
||||
import com.dfsek.terra.api.util.StringUtil;
|
||||
|
||||
import net.querz.nbt.io.NBTDeserializer;
|
||||
import net.querz.nbt.tag.ByteArrayTag;
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
@@ -29,6 +13,18 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
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;
|
||||
import com.dfsek.terra.api.util.StringUtil;
|
||||
|
||||
|
||||
public class SpongeSchematicAddon implements AddonInitializer {
|
||||
@Inject
|
||||
private Platform platform;
|
||||
@@ -36,6 +32,17 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
||||
@Inject
|
||||
private BaseAddon addon;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
platform.getEventManager()
|
||||
@@ -53,7 +60,6 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
||||
.failThrough();
|
||||
}
|
||||
|
||||
|
||||
public SpongeStructure convert(InputStream in, String id) {
|
||||
try {
|
||||
CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag();
|
||||
@@ -88,15 +94,4 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
||||
throw new IllegalArgumentException("Failed to parse Sponge schematic: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.dfsek.terra.addons.sponge;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -12,10 +16,6 @@ import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class SpongeStructure implements Structure {
|
||||
|
||||
@@ -40,13 +40,13 @@ public class SpongeStructure implements Structure {
|
||||
Vector2 r = RotationUtil.rotateVector(new Vector2(x, z), rotation);
|
||||
int rX = r.getBlockX();
|
||||
int rZ = r.getBlockZ();
|
||||
if(FastMath.floorDiv(bX+rX, 16) != chunk.getX() || FastMath.floorDiv(bZ+rZ, 16) != chunk.getZ()) {
|
||||
if(FastMath.floorDiv(bX + rX, 16) != chunk.getX() || FastMath.floorDiv(bZ + rZ, 16) != chunk.getZ()) {
|
||||
continue;
|
||||
}
|
||||
for(int y = 0; y < blocks[z].length; y++) {
|
||||
BlockState state = blocks[x][z][y];
|
||||
if(state == null) continue;
|
||||
world.setBlockData(bX+rX, bY+y, bZ+rZ, state);
|
||||
world.setBlockData(bX + rX, bY + y, bZ + rZ, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class SpongeStructure implements Structure {
|
||||
for(int y = 0; y < blocks[z].length; y++) {
|
||||
BlockState state = blocks[x][z][y];
|
||||
if(state == null) continue;
|
||||
world.setBlockData(bX+rX, bY+y, bZ+rZ, state);
|
||||
world.setBlockData(bX + rX, bY + y, bZ + rZ, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user