Skip to content

Instantly share code, notes, and snippets.

@kbinani
Last active September 27, 2019 16:32
Show Gist options
  • Save kbinani/3e55bbf8f43941d3e6d8ebe301642b5b to your computer and use it in GitHub Desktop.
Save kbinani/3e55bbf8f43941d3e6d8ebe301642b5b to your computer and use it in GitHub Desktop.
type Point = { x: number; z: number };
function createPoint(x: number, z: number) : Point {
return { x, z };
}
function rotatePoint(p: Point, degrees: number) : Point {
const a = -degrees / 180 * Math.PI;
const x = p.x * Math.cos(a) - p.z * Math.sin(a);
const z = p.x * Math.sin(a) + p.z * Math.cos(a);
return createPoint(x, z);
}
function roundPoint(p: Point) : Point {
return createPoint(Math.round(p.x), Math.round(p.z));
}
type Point3 = { x: number; y: number; z: number };
function createPoint3(x: number, y: number, z: number) : Point3 {
return { x, y, z };
}
function assert(condition: boolean, message: string = "") {
if (condition) return;
throw message;
}
const glassBlocks: Point3[] = [];
const stoneBlocks: Point3[] = [];
const airBlocks: Point3[] = [];
const center = createPoint3(62, 63, -81);
const waterfall_steps = [2, 4, 6, 8, 10, 12, 7];
const waterfall_height = waterfall_steps.reduce((p, c) => p + c) - 1;
const lavafall_steps = [2, 4, 6, 8, 5];
const lavafall_height = lavafall_steps.reduce((p, c) => p + c) - 1;
// waterfall tower
const cw: Point[] = [createPoint(0, 1), createPoint(-1, 0), createPoint(0, -1), createPoint(1, 0)];
for (let i = 0; i < cw.length; i++) {
const start = cw[(i + 3) % cw.length];
let x = start.x;
let y = waterfall_height;
let z = start.z;
for (let j = 0; j < waterfall_steps.length; j++) {
const dir = cw[(i + j) % cw.length];
for (let k = 0; k < waterfall_steps[j]; k++) {
const pos = createPoint3(x, y, z);
glassBlocks.push(pos);
const outer = roundPoint(rotatePoint(dir, 90));
const inner = createPoint(-outer.x, -outer.z);
if (k === 0) {
stoneBlocks.push(createPoint3(x + outer.x, y, z + outer.z));
if (j == 0) {
stoneBlocks.push(createPoint3(x + outer.x, y + 1, z + outer.z));
} else {
stoneBlocks.push(createPoint3(x - dir.x, y, z - dir.z));
stoneBlocks.push(createPoint3(x + outer.x - dir.x, y, z + outer.z - dir.z));
}
} else {
stoneBlocks.push(createPoint3(x + inner.x, y, z + inner.z));
stoneBlocks.push(createPoint3(x + outer.x, y, z + outer.z));
}
x += dir.x;
z += dir.z;
y -= 1;
}
}
airBlocks.push(createPoint3(x, y, z));
}
glassBlocks.push(createPoint3(0, waterfall_height + 1, 0)); // cap glass
// lava-fall tower
const ccw = [createPoint(1, 0), createPoint(0, -1), createPoint(-1,0), createPoint(0, 1)];
for (let i = 0; i < ccw.length; i++) {
const start = ccw[(i + 3) % ccw.length];
let x = start.x;
let y = lavafall_height;
let z = start.z;
for (let j = 0; j < lavafall_steps.length; j++) {
const dir = ccw[(i + j) % ccw.length];
for (let k = 0; k < lavafall_steps[j]; k++) {
const pos = createPoint3(x, y, z);
assert(y >= 0);
glassBlocks.push(pos);
const inner = roundPoint(rotatePoint(dir, 90));
const outer = createPoint(-inner.x, -inner.z);
if (k === 0) {
stoneBlocks.push(createPoint3(x + outer.x, y, z + outer.z));
if (j == 0) {
stoneBlocks.push(createPoint3(x + outer.x, y + 1, z + outer.z));
} else {
stoneBlocks.push(createPoint3(x - dir.x, y, z - dir.z));
stoneBlocks.push(createPoint3(x + outer.x - dir.x, y, z + outer.z - dir.z));
}
} else {
stoneBlocks.push(createPoint3(x + inner.x, y, z + inner.z));
stoneBlocks.push(createPoint3(x + outer.x, y, z + outer.z));
}
x += dir.x;
z += dir.z;
y -= 1;
}
}
airBlocks.push(createPoint3(x, y, z));
}
stoneBlocks.push(createPoint3(0, lavafall_height + 1, 0)); // cap stone
stoneBlocks.push(createPoint3(1, lavafall_height + 1, 1));
stoneBlocks.push(createPoint3(1, lavafall_height + 1, -1));
stoneBlocks.push(createPoint3(-1, lavafall_height + 1, 1));
stoneBlocks.push(createPoint3(-1, lavafall_height + 1, -1));
airBlocks.push(createPoint3(0, -1, 0));
glassBlocks.forEach((it) => {
console.log(`setblock ${center.x + it.x} ${center.y + it.y} ${center.z + it.z} glass`);
});
stoneBlocks.forEach((it) => {
console.log(`setblock ${center.x + it.x} ${center.y + it.y} ${center.z + it.z} cobblestone`);
});
airBlocks.forEach((it) => {
console.log(`setblock ${center.x + it.x} ${center.y + it.y} ${center.z + it.z} air`);
});
console.log(`setblock ${center.x} ${center.y + waterfall_height + 2} ${center.z} water`);
console.log(`setblock ${center.x} ${center.y + waterfall_height} ${center.z} lava`);
stoneBlocks.forEach((it) => {
console.error(`setblock ${center.x + it.x} ${center.y + it.y} ${center.z + it.z} air`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment