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.lerariemann.infinity.InfinityMod;
4import net.lerariemann.infinity.dimensions.RandomDimension;
5import net.lerariemann.infinity.util.core.CommonIO;
6import net.lerariemann.infinity.dimensions.RandomFeaturesList;
7import net.lerariemann.infinity.util.InfinityMethods;
8import net.lerariemann.infinity.util.core.ConfigType;
9import net.lerariemann.infinity.util.core.NbtUtils;
10import net.lerariemann.infinity.util.core.RandomProvider;
11import net.minecraft.nbt.*;
12
13import java.util.Random;
14
15public abstract class RandomisedFeature {
16 protected final RandomProvider PROVIDER;
17 protected String id;
18 protected String name;
19 protected Random random;
20 protected RandomFeaturesList parent;
21 protected RandomDimension daddy;
22
23 public RandomisedFeature(RandomFeaturesList lst, String namecore) {
24 this(InfinityMethods.getRandomSeed(lst.random), lst, namecore);
25 }
26
27 public RandomisedFeature(long i, RandomFeaturesList lst, String namecore) {
28 random = new Random(i);
29 id = namecore;
30 name = namecore + "_" + i;
31 parent = lst;
32 daddy = parent.parent.parent;
33 PROVIDER = parent.PROVIDER;
34 }
35
36 public String fullName() {
37 return InfinityMod.MOD_ID + ":" + name;
38 }
39
40 protected void savePlacement() {
41 CompoundTag moredata = new CompoundTag();
42 moredata.put("feature", feature());
43 moredata.put("placement", placement());
44 CommonIO.write(moredata, parent.storagePath + "/worldgen/placed_feature", name + ".json");
45 }
46
47 protected void savePlacement(String feature) {
48 CompoundTag moredata = new CompoundTag();
49 moredata.putString("feature", feature);
50 moredata.put("placement", placement());
51 CommonIO.write(moredata, parent.storagePath + "/worldgen/placed_feature", name + ".json");
52 }
53
54 public CompoundTag genBlockOrFluid() {
55 CompoundTag block2;
56 if (parent.roll("solid_lakes")) {
57 block2 = PROVIDER.randomElement(random, ConfigType.BLOCKS_FEATURES);
58 }
59 else {
60 block2 = NbtUtils.nameToElement(
61 PROVIDER.randomName(random, ConfigType.FLUIDS));
62 }
63 return block2;
64 }
65
66 public void addRandomBlockProvider(CompoundTag config, String key, ConfigType group) {
67 config.put(key, PROVIDER.randomBlockProvider(random, group));
68 }
69 public void addRandomBlock(CompoundTag config, String key, ConfigType group) {
70 CompoundTag block = PROVIDER.randomElement(random, group);
71 config.put(key, block);
72 }
73
74 public void addRandomIntProvider(CompoundTag config, String key, int lbound, int bound) {
75 config.put(key, NbtUtils.randomIntProvider(random, lbound, bound, true));
76 }
77
78 public abstract CompoundTag feature();
79
80 public abstract ListTag placement();
81
82 public CompoundTag feature(CompoundTag config) {
83 CompoundTag res = new CompoundTag();
84 res.putString("type", id);
85 res.put("config", config);
86 return res;
87 }
88}