Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at create-6.0 43 lines 1.2 kB view raw
1package net.lerariemann.infinity.options; 2 3import net.minecraft.nbt.NbtCompound; 4import net.minecraft.nbt.NbtElement; 5 6import java.util.function.Function; 7 8public interface PitchShifter { 9 Function<Float, Float> applier(); 10 11 enum Empty implements PitchShifter { 12 INSTANCE; 13 @Override 14 public Function<Float, Float> applier() { 15 return Function.identity(); 16 } 17 } 18 record Constant(float value) implements PitchShifter { 19 @Override 20 public Function<Float, Float> applier() { 21 return f -> value; 22 } 23 } 24 record Add(float value) implements PitchShifter { 25 @Override 26 public Function<Float, Float> applier() { 27 return f -> f + value; 28 } 29 } 30 31 static PitchShifter decode(NbtCompound comp) { 32 return switch(comp.getString("type")) { 33 case "constant" -> new Constant(getFloat(comp, "value")); 34 case "add" -> new Add(getFloat(comp, "value")); 35 default -> Empty.INSTANCE; 36 }; 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 } 43}