Files
SteamhavenSchematicGenerator.java
Code
1 498
SteamhavenSchematicGenerator.java
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.zip.GZIPOutputStream;
public final class SteamhavenSchematicGenerator {
private static final int WIDTH = 105;
private static final int HEIGHT = 50;
private static final int LENGTH = 105;
private static final String DEFAULT_OUTPUT = "SteamhavenCastle.schem";
private static final Map<String, Integer> PALETTE = new LinkedHashMap<>();
private static final int[] BLOCKS = new int[WIDTH * HEIGHT * LENGTH];
static {
int air = palette("minecraft:air");
for (int i = 0; i < BLOCKS.length; i++) {
BLOCKS[i] = air;
}
}
private SteamhavenSchematicGenerator() {
}
private static int palette(String block) {
Integer id = PALETTE.get(block);
if (id == null) {
id = PALETTE.size();
PALETTE.put(block, id);
}
return id;
}
private static int index(int x, int y, int z) {
return (y * LENGTH + z) * WIDTH + x;
}
private static void setBlock(int x, int y, int z, String block) {
if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT && z >= 0 && z < LENGTH) {
BLOCKS[index(x, y, z)] = palette(block);
}
}
private static void box(int x1, int y1, int z1, int x2, int y2, int z2, String block) {
int minX = Math.max(0, Math.min(x1, x2));
int maxX = Math.min(WIDTH - 1, Math.max(x1, x2));
int minY = Math.max(0, Math.min(y1, y2));
int maxY = Math.min(HEIGHT - 1, Math.max(y1, y2));
int minZ = Math.max(0, Math.min(z1, z2));
int maxZ = Math.min(LENGTH - 1, Math.max(z1, z2));
int blockId = palette(block);
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
for (int x = minX; x <= maxX; x++) {
BLOCKS[index(x, y, z)] = blockId;
}
}
}
}
private static void hollowRoom(int x1, int z1, int x2, int z2, int floorY, int ceilingY, String wall) {
box(x1, floorY, z1, x2, floorY + 1, z2, "minecraft:cut_sandstone");
box(x1, ceilingY, z1, x2, ceilingY + 1, z2, wall);
box(x1, floorY, z1, x1 + 1, ceilingY, z2, wall);
box(x2 - 1, floorY, z1, x2, ceilingY, z2, wall);
box(x1, floorY, z1, x2, ceilingY, z1 + 1, wall);
box(x1, floorY, z2 - 1, x2, ceilingY, z2, wall);
}
private static void cylinderWall(int centerX, int centerZ, int radius, int y1, int y2, String block) {
int radiusSquared = radius * radius;
int innerSquared = (radius - 2) * (radius - 2);
for (int x = centerX - radius; x <= centerX + radius; x++) {
for (int z = centerZ - radius; z <= centerZ + radius; z++) {
int distance = (x - centerX) * (x - centerX) + (z - centerZ) * (z - centerZ);
if (distance >= innerSquared && distance <= radiusSquared) {
for (int y = y1; y <= y2; y++) {
setBlock(x, y, z, block);
}
}
}
}
}
private static void tower(int centerX, int centerZ, int radius, int top) {
cylinderWall(centerX, centerZ, radius, 0, top, "minecraft:cut_sandstone");
int innerRadius = radius - 2;
for (int x = centerX - innerRadius; x <= centerX + innerRadius; x++) {
for (int z = centerZ - innerRadius; z <= centerZ + innerRadius; z++) {
if ((x - centerX) * (x - centerX) + (z - centerZ) * (z - centerZ) <= innerRadius * innerRadius) {
for (int y = 2; y < top; y++) {
setBlock(x, y, z, "minecraft:air");
}
}
}
}
for (int y = 5; y < top; y += 6) {
for (int x = centerX - innerRadius; x <= centerX + innerRadius; x++) {
for (int z = centerZ - innerRadius; z <= centerZ + innerRadius; z++) {
if ((x - centerX) * (x - centerX) + (z - centerZ) * (z - centerZ) <= innerRadius * innerRadius) {
setBlock(x, y, z, "minecraft:spruce_planks");
}
}
}
}
for (int x = centerX - radius + 2; x <= centerX + radius - 2; x += 3) {
setBlock(x, top - 5, centerZ - radius, "minecraft:glass_pane");
setBlock(x, top - 5, centerZ + radius, "minecraft:glass_pane");
}
for (int z = centerZ - radius + 2; z <= centerZ + radius - 2; z += 3) {
setBlock(centerX - radius, top - 5, z, "minecraft:glass_pane");
setBlock(centerX + radius, top - 5, z, "minecraft:glass_pane");
}
for (int x = centerX - radius; x <= centerX + radius; x++) {
for (int z = centerZ - radius; z <= centerZ + radius; z++) {
if ((x - centerX) * (x - centerX) + (z - centerZ) * (z - centerZ) <= radius * radius) {
setBlock(x, top + 1, z, "create:brass_block");
}
}
}
for (int x = centerX - radius; x <= centerX + radius; x += 2) {
for (int z = centerZ - radius; z <= centerZ + radius; z += 2) {
if ((x - centerX) * (x - centerX) + (z - centerZ) * (z - centerZ) <= radius * radius) {
setBlock(x, top + 2, z, "create:brass_block");
}
}
}
}
private static void archRing(int x, int centerZ, int centerY, int radius, String block) {
int innerSquared = (radius - 2) * (radius - 2);
int outerSquared = radius * radius;
for (int z = centerZ - radius; z <= centerZ + radius; z++) {
for (int y = centerY - radius; y <= centerY + radius; y++) {
int distance = (z - centerZ) * (z - centerZ) + (y - centerY) * (y - centerY);
if (distance >= innerSquared && distance <= outerSquared) {
setBlock(x, y, z, block);
}
}
}
}
private static void createTrainHall() {
box(0, 0, 0, WIDTH - 1, 1, LENGTH - 1, "minecraft:stone_bricks");
box(0, 2, 41, WIDTH - 1, 2, 63, "minecraft:polished_andesite");
box(0, 3, 35, WIDTH - 1, 4, 39, "minecraft:cut_sandstone");
box(0, 3, 65, WIDTH - 1, 4, 69, "minecraft:cut_sandstone");
for (int x = 0; x < WIDTH; x++) {
setBlock(x, 3, 50, "minecraft:stone_bricks");
setBlock(x, 3, 53, "minecraft:stone_bricks");
setBlock(x, 4, 50, "create:track");
setBlock(x, 4, 53, "create:track");
}
for (int z = 39; z <= 65; z++) {
box(0, 5, z, 1, 18, z, "minecraft:stone_bricks");
box(WIDTH - 2, 5, z, WIDTH - 1, 18, z, "minecraft:stone_bricks");
}
for (int x = 5; x < WIDTH - 4; x += 8) {
archRing(x, 52, 20, 13, "create:metal_girder");
setBlock(x, 20, 52, "create:brass_casing");
}
for (int x = 4; x < WIDTH - 4; x += 8) {
for (int z : new int[]{40, 64}) {
box(x, 5, z, x + 1, 18, z + 1, "create:andesite_casing");
}
}
for (int x : new int[]{3, WIDTH - 4}) {
archRing(x, 52, 12, 10, "create:brass_block");
box(x, 2, 42, x + 2, 12, 45, "minecraft:sandstone");
box(x, 2, 59, x + 2, 12, 62, "minecraft:sandstone");
}
for (int x = 6; x < WIDTH - 6; x += 10) {
setBlock(x, 16, 40, "minecraft:glass_pane");
setBlock(x, 16, 64, "minecraft:glass_pane");
}
}
private static void createLibrary() {
hollowRoom(10, 72, 40, 97, 2, 22, "minecraft:polished_andesite");
box(12, 3, 74, 38, 3, 95, "minecraft:spruce_planks");
for (int x = 13; x < 39; x += 3) {
box(x, 4, 74, x + 1, 18, 75, "minecraft:bookshelf");
box(x, 4, 95, x + 1, 18, 96, "minecraft:bookshelf");
}
for (int z = 78; z < 95; z += 3) {
box(12, 4, z, 13, 18, z + 1, "minecraft:bookshelf");
box(37, 4, z, 38, 18, z + 1, "minecraft:bookshelf");
}