Files
src
build.gradle
README.md
settings.gradle
Code
8 745
src/main/java/com/kodari/nightcity/NightCityHomebaseGenerator.java
package com.kodari.nightcity;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
public final class NightCityHomebaseGenerator {
private static final int SIZE = 100;
private static final BlockState AIR = BlockState.of("minecraft:air");
private static final BlockState BLACK = BlockState.of("minecraft:black_concrete");
private static final BlockState DEEPSLATE = BlockState.of("minecraft:deepslate_tiles");
private static final BlockState POLISHED_BLACKSTONE = BlockState.of("minecraft:polished_blackstone");
private static final BlockState QUARTZ = BlockState.of("minecraft:smooth_quartz");
private static final BlockState RED = BlockState.of("minecraft:red_concrete");
private static final BlockState CYAN = BlockState.of("minecraft:cyan_concrete");
private static final BlockState GLASS = BlockState.of("minecraft:glass");
private static final BlockState TINTED_GLASS = BlockState.of("minecraft:tinted_glass");
private static final BlockState SEA_LANTERN = BlockState.of("minecraft:sea_lantern");
private static final BlockState GLOWSTONE = BlockState.of("minecraft:glowstone");
private static final BlockState IRON = BlockState.of("minecraft:iron_block");
private static final BlockState OAK_PLANKS = BlockState.of("minecraft:oak_planks");
private static final BlockState OAK_LOG = BlockState.of("minecraft:oak_log");
private static final BlockState SPRUCE = BlockState.of("minecraft:spruce_planks");
private static final BlockState CYAN_CARPET = BlockState.of("minecraft:cyan_carpet");
private static final BlockState RED_CARPET = BlockState.of("minecraft:red_carpet");
private static final BlockState GLASS_PANE = BlockState.of("minecraft:glass_pane");
private static final BlockState CHEST = BlockState.of("minecraft:chest");
private static final BlockState BARREL = BlockState.of("minecraft:barrel");
private static final BlockState CRAFTING = BlockState.of("minecraft:crafting_table");
private static final BlockState FURNACE = BlockState.of("minecraft:furnace");
private static final BlockState BLAST_FURNACE = BlockState.of("minecraft:blast_furnace");
private static final BlockState SMOKER = BlockState.of("minecraft:smoker");
private static final BlockState ANVIL = BlockState.of("minecraft:anvil");
private static final BlockState BED = BlockState.of("minecraft:red_bed");
private static final BlockState BOOKSHELF = BlockState.of("minecraft:bookshelf");
private static final BlockState BREWING = BlockState.of("minecraft:brewing_stand");
private static final BlockState CAULDRON = BlockState.of("minecraft:cauldron");
private static final BlockState ARMOR_STAND = BlockState.of("minecraft:armor_stand");
private static final BlockState TARGET = BlockState.of("minecraft:target");
private static final BlockState FLOWER_POT = BlockState.of("minecraft:flower_pot");
private static final BlockState FERN = BlockState.of("minecraft:fern");
private static final BlockState WATER = BlockState.of("minecraft:water");
private static final BlockState FARMLAND = BlockState.of("minecraft:farmland");
private static final BlockState JUKebox = BlockState.of("minecraft:jukebox");
private static final BlockState ENCHANTING = BlockState.of("minecraft:enchanting_table");
private static final BlockState STONE = BlockState.of("minecraft:stone");
public void generate(Path output) throws IOException {
Schematic schematic = new Schematic(SIZE, SIZE, SIZE);
buildPlaza(schematic);
buildTower(schematic);
buildRooftop(schematic);
buildStreetDetails(schematic);
NbtWriter.write(output, schematic);
}
private void buildPlaza(Schematic s) {
s.fill(8, 0, 8, 91, 2, 91, POLISHED_BLACKSTONE);
s.fill(12, 0, 12, 87, 0, 87, DEEPSLATE);
for (int x = 8; x <= 91; x++) {
for (int z = 8; z <= 91; z++) {
if ((x + z) % 10 == 0) {
s.set(x, 3, z, CYAN_CARPET);
}
}
}
s.fill(8, 3, 47, 91, 3, 52, BLACK);
s.fill(47, 3, 8, 52, 3, 91, BLACK);
for (int i = 0; i < 8; i++) {
int x = 11 + i * 11;
streetLamp(s, x, 4, 11);
streetLamp(s, x, 4, 88);
streetLamp(s, 11, 4, x);
streetLamp(s, 88, 4, x);
}
}
private void streetLamp(Schematic s, int x, int y, int z) {
s.fill(x, y, z, x, y + 3, z, IRON);
s.set(x, y + 4, z, SEA_LANTERN);
s.set(x + 1, y + 4, z, GLASS_PANE);
s.set(x - 1, y + 4, z, GLASS_PANE);
}
private void buildTower(Schematic s) {
for (int floor = 0; floor < 9; floor++) {
int y = 5 + floor * 10;
int inset = floor < 2 ? floor * 2 : 4 + (floor - 2) / 2 * 2;
int min = 15 + inset;
int max = 84 - inset;
buildFloorShell(s, min, max, y);
buildCore(s, y);
furnishFloor(s, floor, min + 3, max - 3, y + 1);
}
buildBaseFacade(s);
}
private void buildFloorShell(Schematic s, int min, int max, int floorY) {
s.fill(min, floorY, min, max, floorY, max, DEEPSLATE);
s.fill(min, floorY + 9, min, max, floorY + 9, max, BLACK);
for (int y = floorY + 1; y < floorY + 9; y++) {
for (int x = min; x <= max; x++) {
s.set(x, y, min, x % 5 == 0 ? RED : (x % 3 == 0 ? GLASS : BLACK));
s.set(x, y, max, x % 5 == 0 ? RED : (x % 3 == 0 ? GLASS : BLACK));
}
for (int z = min + 1; z < max; z++) {
s.set(min, y, z, z % 5 == 0 ? CYAN : (z % 3 == 0 ? GLASS : BLACK));
s.set(max, y, z, z % 5 == 0 ? CYAN : (z % 3 == 0 ? GLASS : BLACK));
}
}
for (int x = min; x <= max; x++) {
if ((x - min) % 4 == 0) {
s.set(x, floorY + 1, min, RED);
s.set(x, floorY + 1, max, RED);
}
}
for (int z = min; z <= max; z++) {
if ((z - min) % 4 == 0) {
s.set(min, floorY + 1, z, CYAN);
s.set(max, floorY + 1, z, CYAN);
}
}
for (int x = min + 2; x < max; x += 7) {
s.set(x, floorY + 8, min, SEA_LANTERN);
s.set(x, floorY + 8, max, SEA_LANTERN);
}
}
private void buildCore(Schematic s, int floorY) {
s.fill(47, floorY + 1, 47, 52, floorY + 8, 52, IRON);
s.fill(48, floorY + 2, 48, 51, floorY + 7, 51, GLASS);
s.set(50, floorY + 2, 48, SEA_LANTERN);
s.set(49, floorY + 7, 51, SEA_LANTERN);
for (int y = floorY + 2; y <= floorY + 7; y += 2) {
s.set(46, y, 49, RED);
s.set(53, y, 50, CYAN);
}
}
private void furnishFloor(Schematic s, int floor, int min, int max, int y) {
int left = min + 2;
int right = max - 2;
int front = min + 2;
int back = max - 2;
switch (floor) {
case 0 -> lobby(s, left, right, front, back, y);
case 1 -> workshop(s, left, right, front, back, y);
case 2 -> storage(s, left, right, front, back, y);
case 3 -> kitchen(s, left, right, front, back, y);
case 4 -> lounge(s, left, right, front, back, y);
case 5 -> greenhouse(s, left, right, front, back, y);
case 6 -> armory(s, left, right, front, back, y);
case 7 -> medbay(s, left, right, front, back, y);
default -> penthouse(s, left, right, front, back, y);
}
}
private void lobby(Schematic s, int left, int right, int front, int back, int y) {
s.fill(left, y, front + 5, right, y, front + 7, QUARTZ);
for (int x = left + 3; x < right - 2; x += 5) {
furniture(s, x, y + 1, front + 4, OAK_PLANKS);
s.set(x, y + 2, front + 4, RED_CARPET);
}
s.fill(left + 8, y + 1, back - 6, right - 8, y + 1, back - 4, BLACK);
s.fill(left + 10, y + 2, back - 6, right - 10, y + 2, back - 5, RED_CARPET);
for (int x = left + 10; x <= right - 10; x += 4) {
s.set(x, y + 1, back - 3, SEA_LANTERN);
}
s.set(left + 3, y + 1, back - 8, CHEST);
s.set(left + 4, y + 1, back - 8, CHEST);
s.fill(right - 8, y + 1, front + 2, right - 6, y + 3, front + 4, IRON);
s.set(right - 7, y + 4, front + 3, RED);
}
private void workshop(Schematic s, int left, int right, int front, int back, int y) {
for (int x = left + 2; x < right - 2; x += 4) {
s.set(x, y + 1, front + 2, CRAFTING);
s.set(x + 1, y + 1, front + 2, ANVIL);
s.set(x, y + 1, front + 3, CHEST);
s.set(x + 1, y + 1, front + 3, BARREL);
}
for (int z = front + 7; z < back - 4; z += 3) {
s.set(left + 3, y + 1, z, FURNACE);
s.set(left + 4, y + 1, z, BLAST_FURNACE);
s.set(left + 5, y + 1, z, SMOKER);
}
s.fill(right - 10, y + 1, back - 8, right - 4, y + 1, back - 3, IRON);
s.set(right - 7, y + 2, back - 6, SEA_LANTERN);
}
private void storage(Schematic s, int left, int right, int front, int back, int y) {
for (int x = left + 2; x < right - 2; x += 3) {
for (int z = front + 2; z < back - 2; z += 4) {
s.set(x, y + 1, z, BARREL);
s.set(x, y + 2, z, BARREL);
if ((x + z) % 2 == 0) {
s.set(x + 1, y + 1, z, CHEST);
}
}
}