Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
1package net.lerariemann.infinity.dimensions;
2
3import net.lerariemann.infinity.util.core.CommonIO;
4import net.lerariemann.infinity.util.core.ConfigType;
5import net.minecraft.nbt.CompoundTag;
6import net.minecraft.nbt.ListTag;
7import java.util.Random;
8
9public class RandomStructureSet {
10 public RandomStructure parent;
11 public Random random;
12 public CompoundTag data;
13
14 RandomStructureSet(RandomStructure str) {
15 parent = str;
16 random = parent.random;
17 data = new CompoundTag();
18 data.put("structures", structures());
19 data.put("placement", placement());
20 }
21
22 void save() {
23 CommonIO.write(data, parent.parent.parent.getStoragePath() + "/worldgen/structure_set", parent.name + ".json");
24 }
25
26 ListTag structures() {
27 ListTag res = new ListTag();
28 CompoundTag structure = new CompoundTag();
29 structure.putString("structure", parent.fullname);
30 structure.putInt("weight", 1);
31 res.add(structure);
32 return res;
33 }
34
35 int f(Random r, int mx, int med) {
36 return Math.max(0, Math.min(mx, (int)(Math.floor(r.nextExponential()*med))));
37 }
38
39 CompoundTag placement() {
40 CompoundTag res = new CompoundTag();
41 res.putInt("salt", random.nextInt(Integer.MAX_VALUE));
42 res.putFloat("frequency", random.nextFloat());
43 String type = parent.parent.PROVIDER.randomName(random, ConfigType.STRUCTURE_PLACEMENT_TYPES);
44 res.putString("type", type);
45 switch (type) {
46 case "minecraft:random_spread" -> {
47 if (parent.roll("triangular_spread")) res.putString("spread_type", "triangular");
48 int a = 6 + f(random, 4095, 6);
49 int b = f(random, 4095, 6);
50 if (a == b) a+=1;
51 res.putInt("spacing", Math.max(a, b));
52 res.putInt("separation", Math.min(a, b));
53 }
54 case "minecraft:concentric_rings" -> {
55 res.putInt("distance", f(random, 1023, 8));
56 res.putInt("count", 1 + f(random, 4094, 64));
57 res.putInt("spread", 1 + f(random, 1023, 3));
58 res.putString("preferred_biomes", parent.parent.fullname);
59 }
60 }
61 return res;
62 }
63}