Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
1package net.lerariemann.infinity.dimensions.features;
2
3import net.minecraft.nbt.*;
4
5import java.util.List;
6
7public class Placement {
8 public ListTag data;
9
10 public Placement() {
11 data = new ListTag();
12 }
13
14 public void addSingleRule(String name, String name_param, Tag b) {
15 data.add(singleRule(name, name_param, b));
16 }
17
18 public void addEmptyRule(String name) {
19 data.add(ofType(name));
20 }
21
22 public void addBlockPredicateFilter(CompoundTag predicate) {
23 addSingleRule("block_predicate_filter", "predicate", predicate);
24 }
25
26 public void addCount(int b) {
27 addSingleRule("count", "count", IntTag.valueOf(b));
28 }
29
30 public void addCountEveryLayer(int b) {
31 addSingleRule("count_on_every_layer", "count", IntTag.valueOf(b));
32 }
33
34 public void addRarityFilter(int b) {
35 addSingleRule("rarity_filter", "chance", IntTag.valueOf(b));
36 }
37
38 public void addWaterDepthFilter(int b) {
39 addSingleRule("surface_water_depth_filter", "max_water_depth", IntTag.valueOf(b));
40 }
41
42 public void addInSquare() {
43 addEmptyRule("in_square");
44 }
45
46 public void addBiome() {
47 addEmptyRule("biome");
48 }
49
50 public void addHeightmap(String s) {
51 addSingleRule("heightmap", "heightmap", StringTag.valueOf(s));
52 }
53
54 public void addHeightRange(CompoundTag heightProvider) {
55 addSingleRule("height_range", "height", heightProvider);
56 }
57
58 public static ListTag everylayerBiome(int count) {
59 Placement res = new Placement();
60 res.addCountEveryLayer(count);
61 res.addBiome();
62 return res.data;
63 }
64
65 public static ListTag uniform(int count) {
66 Placement res = new Placement();
67 res.addCount(count);
68 res.addInSquare();
69 res.addHeightRange(fullHeightRange());
70 return res.data;
71 }
72
73 public static ListTag floating(int chance, int a, int b) {
74 Placement res = new Placement();
75 res.addRarityFilter(chance);
76 if (a==b) a+=1;
77 res.addHeightRange(uniformHeightRange(Math.min(a, b), Math.max(a, b)));
78 res.addBlockPredicateFilter(not(ofType("solid")));
79 res.addBiome();
80 return res.data;
81 }
82
83 public static CompoundTag singleRule(String type, String name_param, Tag b) {
84 CompoundTag res = ofType(type);
85 res.put(name_param, b);
86 return res;
87 }
88
89 public static CompoundTag ofType(String type) {
90 CompoundTag res = new CompoundTag();
91 res.putString("type", "minecraft:"+type);
92 return res;
93 }
94
95 public static CompoundTag fullHeightRange() {
96 CompoundTag res = ofType("uniform");
97 CompoundTag max_inclusive = new CompoundTag();
98 CompoundTag min_inclusive = new CompoundTag();
99 max_inclusive.putInt("below_top", 0);
100 min_inclusive.putInt("above_bottom", 0);
101 res.put("max_inclusive", max_inclusive);
102 res.put("min_inclusive", min_inclusive);
103 return res;
104 }
105
106 public static CompoundTag uniformHeightRange(int min, int max) {
107 return heightRange(min, max, "uniform");
108 }
109
110 public static CompoundTag heightRange(int min, int max, String type) {
111 CompoundTag res = ofType(type);
112 CompoundTag max_inclusive = new CompoundTag();
113 CompoundTag min_inclusive = new CompoundTag();
114 max_inclusive.putInt("absolute", max);
115 min_inclusive.putInt("absolute", min);
116 res.put("max_inclusive", max_inclusive);
117 res.put("min_inclusive", min_inclusive);
118 return res;
119 }
120
121 public static CompoundTag matchingBlocks(String block) {
122 return singleRule("matching_blocks", "blocks", StringTag.valueOf(block));
123 }
124
125 public static CompoundTag matchingFluids(String s) {
126 return singleRule("matching_fluids", "fluids", StringTag.valueOf(s));
127 }
128 public static CompoundTag not(CompoundTag predicate) {
129 return singleRule("not", "predicate", predicate);
130 }
131
132 public static ListTag offsetToNbt(List<Integer> offset) {
133 ListTag offsetnbt = new ListTag();
134 offset.forEach(a -> offsetnbt.add(IntTag.valueOf(a)));
135 return offsetnbt;
136 }
137}