Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.

Merge branch 'master' into architectury/1.21.3

+29 -24
+2 -2
common/src/main/java/net/lerariemann/infinity/block/entity/InfinityPortalBlockEntity.java
··· 154 154 155 155 public void readNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { 156 156 super.readNbt(tag, registryLookup); 157 - if (tag.contains("Dimension", NbtElement.NUMBER_TYPE)) { //conversion from legacy formats 157 + if (tag.getType("Dimension") == NbtElement.NUMBER_TYPE) { //conversion from legacy formats 158 158 this.portalColor = NbtUtils.getInt(tag, "Dimension") & 0xFFFFFF; 159 159 if (tag.contains("DimensionName")) { 160 160 this.dimension = Identifier.of(NbtUtils.getString(tag, "DimensionName")); 161 161 } 162 162 else this.dimension = InfinityMethods.getDimId(this.portalColor); 163 163 } 164 - else if (tag.contains("Dimension", NbtElement.STRING_TYPE)) { //new better format 164 + else if (tag.getType("Dimension") == NbtElement.STRING_TYPE) { //new better format 165 165 this.dimension = Identifier.of(NbtUtils.getString(tag, "Dimension")); 166 166 this.portalColor = NbtUtils.getInt(tag, "Color", (world != null ? PortalColorApplier.of(dimension, world.getServer()) : 167 167 PortalColorApplier.of(dimension, new NbtCompound())).apply(pos) & 0xFFFFFF);
+1 -1
common/src/main/java/net/lerariemann/infinity/dimensions/RandomCarver.java
··· 66 66 res.add(parent.parent.default_block.get("Name")); 67 67 for (NbtCompound a : parent.parent.additional_blocks) res.add(a.get("Name")); 68 68 res.add(parent.parent.default_fluid.get("Name")); 69 - res.add(NbtString.of(parent.parent.underwater.get(parent.fullname).getString("Name"))); 69 + res.add(NbtString.of(NbtUtils.getString(parent.parent.underwater.get(parent.fullname), "Name"))); 70 70 return res; 71 71 } 72 72 }
+1 -1
common/src/main/java/net/lerariemann/infinity/dimensions/RandomDimension.java
··· 369 369 Map<String, NbtList> tags = new HashMap<>(); 370 370 for (String s : structure_ids.keySet()) for (String ss : dictionary.getKeys()) if (s.contains(ss)) { 371 371 for (NbtElement e : (NbtList) Objects.requireNonNull(dictionary.get(ss))) { 372 - String t = e.asString(); 372 + String t = String.valueOf(e); 373 373 if (!tags.containsKey(t)) tags.put(t, new NbtList()); 374 374 structure_ids.get(s).forEach(fullname -> tags.get(t).add(NbtString.of(fullname))); 375 375 }
+3 -3
common/src/main/java/net/lerariemann/infinity/dimensions/RandomNoisePreset.java
··· 48 48 data.putBoolean("disable_mob_generation", false); 49 49 data.putBoolean("legacy_random_source", false); 50 50 data.put("default_block", parent.default_block); 51 - data.put("default_fluid", NbtUtils.nameToElement(parent.default_fluid.getString("Name"))); 51 + data.put("default_fluid", NbtUtils.nameToElement(NbtUtils.getString(parent.default_fluid, "Name"))); 52 52 data.putInt("sea_level", parent.sea_level); 53 53 data.put("noise", noise(dim)); 54 54 data.put("noise_router", getRouter(noise_router)); ··· 174 174 files.forEach(p -> { 175 175 if (p.toString().contains("surface_rule") && p.toFile().isFile()) { 176 176 NbtCompound compound = CommonIO.readSurfaceRule(p.toFile(), parent.sea_level); 177 - NbtList biomes = compound.getList("biomes", NbtElement.STRING_TYPE); 177 + NbtList biomes = NbtUtils.getList(compound, "biomes", NbtElement.STRING_TYPE); 178 178 NbtList biomestoadd = new NbtList(); 179 179 for (NbtElement b : biomes) { 180 180 if (parent.vanilla_biomes.contains(b.asString())) biomestoadd.add(b); 181 181 } 182 182 if (!biomestoadd.isEmpty()) { 183 - NbtCompound rule = compound.getCompound("rule"); 183 + NbtCompound rule = NbtUtils.getCompound(compound, "rule"); 184 184 sequence.add(ruleWrap(biomestoadd, rule)); 185 185 } 186 186 }
+2 -1
common/src/main/java/net/lerariemann/infinity/mixin/core/LevelPropertiesMixin.java
··· 3 3 import com.llamalad7.mixinextras.injector.wrapoperation.Operation; 4 4 import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; 5 5 import net.lerariemann.infinity.InfinityMod; 6 + import net.lerariemann.infinity.util.core.NbtUtils; 6 7 import net.minecraft.nbt.NbtCompound; 7 8 import net.minecraft.nbt.NbtElement; 8 9 import net.minecraft.world.level.LevelProperties; ··· 20 21 if (instance.isEmpty()) return; 21 22 NbtCompound c = ((NbtCompound) instance.get()); 22 23 if (c.contains("dimensions")) { 23 - NbtCompound d = c.getCompound("dimensions"); 24 + NbtCompound d = NbtUtils.getCompound(c, "dimensions"); 24 25 NbtCompound newD = new NbtCompound(); 25 26 d.getKeys().stream().filter(s -> !s.startsWith(InfinityMod.MOD_ID + ":")).forEach(key -> newD.put(key, d.get(key))); 26 27 c.put("dimensions", newD);
+1 -1
common/src/main/java/net/lerariemann/infinity/options/InfinityOptions.java
··· 98 98 } 99 99 public int getHauntingTicks(Random random) { 100 100 if (!isHaunted()) return -2; 101 - if (data.contains("haunting_ticks")) return data.getInt("haunting_ticks"); 101 + if (data.contains("haunting_ticks")) return NbtUtils.getInt(data, "haunting_ticks"); 102 102 return random.nextBetween(NbtUtils.getInt(data, "min_haunting_ticks", 20), NbtUtils.getInt(data, "max_haunting_ticks", 200)); 103 103 } 104 104
+4 -7
common/src/main/java/net/lerariemann/infinity/options/PitchShifter.java
··· 5 5 6 6 import java.util.function.Function; 7 7 8 + import static net.lerariemann.infinity.util.core.NbtUtils.getFloat; 9 + 8 10 public interface PitchShifter { 9 11 Function<Float, Float> applier(); 10 12 ··· 30 32 31 33 static PitchShifter decode(NbtCompound comp) { 32 34 return switch(comp.getString("type")) { 33 - case "constant" -> new Constant(getFloat(comp, "value")); 34 - case "add" -> new Add(getFloat(comp, "value")); 35 + case "constant" -> new Constant(getFloat(comp, "value", 1)); 36 + case "add" -> new Add(getFloat(comp, "value", 1)); 35 37 default -> Empty.INSTANCE; 36 38 }; 37 - } 38 - 39 - static float getFloat(NbtCompound comp, String s) { 40 - if (!comp.contains(s, NbtElement.FLOAT_TYPE)) return 1; 41 - return comp.getFloat(s); 42 39 } 43 40 }
+1 -1
common/src/main/java/net/lerariemann/infinity/options/PortalColorApplier.java
··· 48 48 @Override 49 49 public int apply(BlockPos pos) { 50 50 int mod = InfinityMethods.properMod(pos.getX() + pos.getY() + pos.getZ(), values.size()); 51 - return values.getInt(mod); 51 + return NbtUtils.getInt(values, mod); 52 52 } 53 53 } 54 54
+2 -2
common/src/main/java/net/lerariemann/infinity/util/config/Amendment.java
··· 44 44 case "containing" -> new ContainingSelector(NbtUtils.getString(data, "containing")); 45 45 case "matching" -> new MatchingSelector(NbtUtils.getString(data, "matching")); 46 46 case "matching_block_tag" -> new MatchingBlockTagSelector(NbtUtils.getString(data, "matching")); 47 - case "matching_any" -> new MatchingAnySelector(data.getList("matching", NbtElement.STRING_TYPE) 47 + case "matching_any" -> new MatchingAnySelector(NbtUtils.getList(data, "matching", NbtElement.STRING_TYPE) 48 48 .stream().map(e->(NbtString)e).map(NbtString::asString).toList()); 49 49 default -> { 50 50 InfinityMod.LOGGER.warn("Unknown amendment selector type: {}", selectorType); ··· 71 71 Map<ConfigType, List<Amendment>> data = new HashMap<>(); 72 72 NbtCompound rawData = CommonIO.read(InfinityMod.amendmentPath); 73 73 AtomicInteger i = new AtomicInteger(); 74 - for (NbtElement e : rawData.getList("elements", NbtElement.COMPOUND_TYPE)) { 74 + for (NbtElement e : NbtUtils.getList(rawData,"elements", NbtElement.COMPOUND_TYPE)) { 75 75 Amendment amd = Amendment.of((NbtCompound)e); 76 76 if (amd == null) continue; 77 77 i.getAndIncrement();
+2 -1
common/src/main/java/net/lerariemann/infinity/util/config/ConfigManager.java
··· 3 3 import dev.architectury.platform.Platform; 4 4 import net.lerariemann.infinity.InfinityMod; 5 5 import net.lerariemann.infinity.util.core.CommonIO; 6 + import net.lerariemann.infinity.util.core.NbtUtils; 6 7 import net.minecraft.nbt.NbtCompound; 7 8 import net.minecraft.nbt.NbtElement; 8 9 import net.minecraft.nbt.NbtList; ··· 130 131 static void evictOldFiles() { 131 132 InfinityMod.LOGGER.info("Evicting old files"); 132 133 NbtCompound c = CommonIO.read(InfinityMod.utilPath.resolve("evicted_files.json")); 133 - NbtList l = c.getList("content", NbtElement.STRING_TYPE); 134 + NbtList l = NbtUtils.getList(c,"content", NbtElement.STRING_TYPE); 134 135 try { 135 136 for (NbtElement e : l) { 136 137 Path path1 = configPath.resolve(e.asString());
+2 -2
common/src/main/java/net/lerariemann/infinity/util/config/SurfaceRuleScanner.java
··· 75 75 case "condition", "minecraft:condition" -> { 76 76 NbtCompound next = NbtUtils.getCompound(rule,"then_run"); 77 77 NbtCompound c = NbtUtils.getCompound(rule, "if_true"); 78 - if (c.getString("type").contains("above_preliminary_surface")) { 78 + if (NbtUtils.getString(c, "type").contains("above_preliminary_surface")) { 79 79 add(next, where); 80 80 } 81 - else if (!c.getString("type").contains("biome")) { 81 + else if (!NbtUtils.getString(c, "type").contains("biome")) { 82 82 TreeLeaf l = addOfRule(c, where, false); 83 83 add(next, l); 84 84 }
+1 -1
common/src/main/java/net/lerariemann/infinity/util/core/CommonIO.java
··· 147 147 File file = modDir.toPath().resolve(fullname).toFile(); 148 148 if (file.exists()) { 149 149 NbtCompound base = read(file); 150 - base.getList("elements", NbtElement.COMPOUND_TYPE).stream().map(e -> (NbtCompound)e).forEach(compounds::add); 150 + NbtUtils.getList(base,"elements", NbtElement.COMPOUND_TYPE).stream().map(e -> (NbtCompound)e).forEach(compounds::add); 151 151 } 152 152 } 153 153 return compounds;
+1 -1
common/src/main/java/net/lerariemann/infinity/util/core/Easterizer.java
··· 32 32 typeMap.put(name, NbtUtils.getString(compound, "type")); 33 33 if (compound.contains("aliases", NbtElement.LIST_TYPE)) { 34 34 String finalName = name; 35 - compound.getList("aliases", NbtElement.STRING_TYPE) 35 + NbtUtils.getList(compound, "aliases", NbtElement.STRING_TYPE) 36 36 .stream() 37 37 .map(e -> (NbtString)e) 38 38 .map(NbtString::asString)
+6
common/src/main/java/net/lerariemann/infinity/util/core/NbtUtils.java
··· 46 46 static boolean getBoolean(NbtCompound data, String key) { 47 47 return data.getBoolean(key); 48 48 } 49 + static NbtList getList(NbtCompound data, String key, byte nbttype) { 50 + return data.getList(key, nbttype); 51 + } 52 + static int getInt(NbtList data, int key) { 53 + return data.getInt(key); 54 + } 49 55 50 56 static String elementToName(NbtElement e) { 51 57 if (e instanceof NbtCompound compound) return NbtUtils.getString(compound, "Name");