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.InfinityMod;
4import net.lerariemann.infinity.util.core.CommonIO;
5import net.lerariemann.infinity.util.core.NbtUtils;
6import net.minecraft.nbt.CompoundTag;
7import net.minecraft.nbt.ListTag;
8import net.minecraft.nbt.StringTag;
9import java.util.Random;
10
11public class RandomCarver {
12 public String name;
13 public String fullname;
14 private final Random random;
15 public RandomBiome parent;
16
17 RandomCarver(RandomBiome b, boolean cave) {
18 parent = b;
19 String s = cave ? "cave" : "canyon";
20 name = s + "_" + b.id;
21 fullname = InfinityMod.MOD_ID + ":" + name;
22 random = b.random;
23 CompoundTag res = new CompoundTag();
24 res.putString("type", "minecraft:" + s);
25 CompoundTag config = new CompoundTag();
26 config.putFloat("probability", (float)Math.min(1.0, random.nextExponential()*(cave ? 0.1 : 0.02)));
27 CompoundTag lava_level = new CompoundTag();
28 lava_level.putInt("above_bottom", 0);
29 config.put("lava_level", lava_level);
30 config.put("y", y());
31 config.put("replaceable", replaceable());
32 if (cave) {
33 putScale(config, "yScale", 3.0f);
34 putScale(config, "horizontal_radius_multiplier", 2.5f);
35 putScale(config, "vertical_radius_multiplier", 2.5f);
36 config.put("floor_level", NbtUtils.randomFloatProvider(random, -1.0f, 1.0f));
37 }
38 else {
39 putScale(config, "yScale", 3.0f);
40 config.put("vertical_rotation", NbtUtils.randomFloatProvider(random, -1.0f, 1.0f));
41 CompoundTag shape = new CompoundTag();
42 putScale(shape, "distance_factor", 2.0f);
43 putScale(shape, "thickness", 3.0f);
44 putScale(shape, "horizontal_radius_factor", 2.0f);
45 shape.putFloat("vertical_radius_default_factor", random.nextFloat(0.5f, 2.0f));
46 shape.putFloat("vertical_radius_center_factor", random.nextFloat(0.5f, 2.0f));
47 shape.putInt("width_smoothness", 1 + random.nextInt(8));
48 config.put("shape", shape);
49 }
50 res.put("config", config);
51 CommonIO.write(res, parent.parent.getStoragePath() + "/worldgen/configured_carver", name + ".json");
52 }
53
54 void putScale(CompoundTag config, String key, float bound) {
55 config.put(key, NbtUtils.randomFloatProvider(random, 1/bound, bound));
56 }
57
58 CompoundTag y() {
59 int min_y = parent.parent.min_y;
60 return NbtUtils.randomHeightProvider(random, min_y, min_y + parent.parent.height, true, false);
61 }
62
63 ListTag replaceable() {
64 ListTag res = new ListTag();
65 res.add(parent.parent.default_block.get("Name"));
66 for (CompoundTag a : parent.parent.additional_blocks) res.add(a.get("Name"));
67 res.add(parent.parent.default_fluid.get("Name"));
68 res.add(StringTag.valueOf(NbtUtils.getString(parent.parent.underwater.get(parent.fullname), "Name")));
69 return res;
70 }
71}