/
worlds.clj
79 lines (66 loc) · 2.81 KB
/
worlds.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(ns lambdaisland.witchcraft.glowstone.worlds
"Generate new worlds based on simple xyz->material functions
Quite naive, more a proof of concept."
(:refer-clojure :exclude [bean])
(:require [lambdaisland.witchcraft :as wc]
[lambdaisland.witchcraft.util :as util]
[lambdaisland.witchcraft.safe-bean :refer [bean bean->]]))
(set! *warn-on-reflection* true)
(defn create-world
"Create a new game world based on a generator function
`gen-fn` is a function which takes (x y z) and returns a material."
[name gen-fn spawn-loc]
(.createWorld
(wc/server)
(.generator (org.bukkit.WorldCreator. name)
(proxy [net.glowstone.generator.GlowChunkGenerator] [(into-array org.bukkit.generator.BlockPopulator [])]
(generateChunkData [world random chunk-x chunk-z biomes]
(let [chunk (net.glowstone.generator.GlowChunkData. world)]
(doseq [^long x (range 16)
^long y (range 128)
^long z (range 16)
:let [real-x (+ (* chunk-x 16) x)
real-z (+ (* chunk-z 16) z)
material (gen-fn real-x y real-z #_(.getBiome biomes real-x real-z))]
:when material]
(.setBlock chunk x y z (wc/material material)))
chunk)))))
(.setSpawnLocation (wc/world name) (wc/location (assoc spawn-loc :world (wc/world name)))))
(comment
(create-world "stone-flats"
(fn [x y z]
(when (or (< y 5))
:stone))
{:x 0 :y 6 :z 0})
(create-world "waterworld"
(fn [x y z]
(cond
(< 20 y)
nil
(< (.distance (util/vec3 0 y 0) (util/vec3 x y z)) 30)
(if (= 20 y)
:grass
:dirt)
:else
:water))
{:x 0 :y 21 :z 0}) (create-world "stone-flats"
(fn [x y z]
(when (or (< y 5))
:stone))
{:x 0 :y 6 :z 0})
(create-world "waterworld"
(fn [x y z]
(cond
(< 20 y)
nil
(< (.distance (util/vec3 0 y 0) (util/vec3 x y z)) 30)
(if (= 20 y)
:grass
:dirt)
:else
:water))
{:x 0 :y 21 :z 0})
(teleport {:world (world "waterworld")
:y 22
:x 0
:z 0}))