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