From a92e165058f378593ee13ae523277c3884a8261b Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Thu, 3 Mar 2022 20:19:26 +0100 Subject: [PATCH] Update to 1.18.2 --- .github/workflows/build.yml | 1 - gradle.properties | 10 +-- .../nucleoid/fantasy/RemoveFromRegistry.java | 4 + .../xyz/nucleoid/fantasy/RuntimeWorld.java | 2 +- .../nucleoid/fantasy/RuntimeWorldConfig.java | 23 ++++-- .../nucleoid/fantasy/RuntimeWorldManager.java | 5 +- .../mixin/registry/SimpleRegistryMixin.java | 75 ++++++++++++------- .../fantasy/util/VoidChunkGenerator.java | 74 ++++++++++++------ .../data/fantasy/dimension_type/default.json | 2 +- 9 files changed, 129 insertions(+), 67 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8910272..70db019 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,6 @@ name: Build on: push: - branches: [ 1.17, 1.18 ] jobs: build: diff --git a/gradle.properties b/gradle.properties index e5e058e..8a37eb3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,14 +2,14 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties -minecraft_version=1.18-pre6 -yarn_mappings=1.18-pre6+build.3 -loader_version=0.12.5 +minecraft_version=1.18.2 +yarn_mappings=1.18.2+build.1 +loader_version=0.13.3 # Mod Properties -mod_version=0.4.3 +mod_version=0.4.4 maven_group=xyz.nucleoid archives_base_name=fantasy # Dependencies -fabric_version=0.42.9+1.18 +fabric_version=0.47.8+1.18.2 diff --git a/src/main/java/xyz/nucleoid/fantasy/RemoveFromRegistry.java b/src/main/java/xyz/nucleoid/fantasy/RemoveFromRegistry.java index d3a09e8..548a6c9 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RemoveFromRegistry.java +++ b/src/main/java/xyz/nucleoid/fantasy/RemoveFromRegistry.java @@ -17,4 +17,8 @@ static boolean remove(SimpleRegistry registry, T value) { boolean remove(T value); boolean remove(Identifier key); + + void setFrozen(boolean value); + + boolean isFrozen(); } diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorld.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorld.java index 3b6a03e..7d3a0fc 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorld.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorld.java @@ -20,7 +20,7 @@ class RuntimeWorld extends ServerWorld { server, Util.getMainWorkerExecutor(), ((MinecraftServerAccess) server).getSession(), new RuntimeWorldProperties(server.getSaveProperties(), config), registryKey, - config.createDimensionOptions(server).getDimensionType(), + config.createDimensionOptions(server).getDimensionTypeSupplier(), VoidWorldProgressListener.INSTANCE, config.getGenerator(), false, diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java index 347ad93..3bd62b0 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java @@ -2,8 +2,8 @@ import com.google.common.base.Preconditions; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryEntry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.Difficulty; import net.minecraft.world.GameRules; @@ -22,7 +22,7 @@ public final class RuntimeWorldConfig { private long seed = 0; private RegistryKey dimensionTypeKey = Fantasy.DEFAULT_DIM_TYPE; - private DimensionType dimensionType; + private RegistryEntry dimensionType; private ChunkGenerator generator = null; private long timeOfDay = 6000; private Difficulty difficulty = Difficulty.NORMAL; @@ -39,12 +39,19 @@ public RuntimeWorldConfig setSeed(long seed) { return this; } - public RuntimeWorldConfig setDimensionType(DimensionType dimensionType) { + public RuntimeWorldConfig setDimensionType(RegistryEntry dimensionType) { this.dimensionType = dimensionType; this.dimensionTypeKey = null; return this; } + @Deprecated + public RuntimeWorldConfig setDimensionType(DimensionType dimensionType) { + this.dimensionType = RegistryEntry.of(dimensionType); + this.dimensionTypeKey = null; + return this; + } + public RuntimeWorldConfig setDimensionType(RegistryKey dimensionType) { this.dimensionTypeKey = dimensionType; this.dimensionType = null; @@ -110,14 +117,14 @@ public long getSeed() { } public DimensionOptions createDimensionOptions(MinecraftServer server) { - DimensionType dimensionType = this.resolveDimensionType(server); - return new DimensionOptions(() -> dimensionType, this.generator); + var dimensionType = this.resolveDimensionType(server); + return new DimensionOptions(dimensionType, this.generator); } - private DimensionType resolveDimensionType(MinecraftServer server) { - DimensionType dimensionType = this.dimensionType; + private RegistryEntry resolveDimensionType(MinecraftServer server) { + var dimensionType = this.dimensionType; if (dimensionType == null) { - dimensionType = server.getRegistryManager().get(Registry.DIMENSION_TYPE_KEY).get(this.dimensionTypeKey); + dimensionType = server.getRegistryManager().get(Registry.DIMENSION_TYPE_KEY).getEntry(this.dimensionTypeKey).orElse(null); Preconditions.checkNotNull(dimensionType, "invalid dimension type " + this.dimensionTypeKey); } return dimensionType; diff --git a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java index 75cb34c..738196b 100644 --- a/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java +++ b/src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java @@ -30,7 +30,10 @@ RuntimeWorld add(RegistryKey worldKey, RuntimeWorldConfig config, Runtime DimensionOptions options = config.createDimensionOptions(this.server); SimpleRegistry dimensionsRegistry = getDimensionsRegistry(this.server); + boolean isFrozen = ((RemoveFromRegistry) dimensionsRegistry).isFrozen(); + ((RemoveFromRegistry) dimensionsRegistry).setFrozen(false); dimensionsRegistry.add(RegistryKey.of(Registry.DIMENSION_KEY, worldKey.getValue()), options, Lifecycle.stable()); + ((RemoveFromRegistry) dimensionsRegistry).setFrozen(isFrozen); RuntimeWorld world = new RuntimeWorld(this.server, worldKey, config, style); @@ -70,6 +73,6 @@ void delete(ServerWorld world) { private static SimpleRegistry getDimensionsRegistry(MinecraftServer server) { GeneratorOptions generatorOptions = server.getSaveProperties().getGeneratorOptions(); - return generatorOptions.getDimensions(); + return (SimpleRegistry) generatorOptions.getDimensions(); } } diff --git a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java index e85bb4b..fdaed1e 100644 --- a/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java +++ b/src/main/java/xyz/nucleoid/fantasy/mixin/registry/SimpleRegistryMixin.java @@ -5,57 +5,78 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.ObjectList; import net.minecraft.util.Identifier; +import net.minecraft.util.registry.RegistryEntry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.util.registry.SimpleRegistry; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import xyz.nucleoid.fantasy.RemoveFromRegistry; +import java.util.List; import java.util.Map; +import java.util.Optional; @Mixin(SimpleRegistry.class) -public class SimpleRegistryMixin implements RemoveFromRegistry { - @Shadow - @Final - private ObjectList rawIdToEntry; - @Shadow - @Final - private Object2IntMap entryToRawId; - @Shadow - @Final - private BiMap idToEntry; - @Shadow - @Final - private BiMap, T> keyToEntry; - @Shadow - @Final - private Map entryToLifecycle; - - @Shadow - protected Object[] randomEntries; +public abstract class SimpleRegistryMixin implements RemoveFromRegistry { + + @Shadow @Final private Map> valueToEntry; + + @Shadow @Nullable private Map> unfrozenValueToEntry; + + @Shadow @Final private Map> idToEntry; + + @Shadow @Final private Map, RegistryEntry.Reference> keyToEntry; + + @Shadow @Final private Map entryToLifecycle; + + @Shadow @Final private ObjectList> rawIdToEntry; + + @Shadow @Final private Object2IntMap entryToRawId; + + @Shadow public abstract Optional> getEntry(int rawId); + + @Shadow private boolean frozen; + + @Shadow @Nullable private List> cachedEntries; @Override public boolean remove(T entry) { + var registryEntry = this.valueToEntry.get(entry); int rawId = this.entryToRawId.removeInt(entry); if (rawId == -1) { return false; } - this.idToEntry.inverse().remove(entry); - this.keyToEntry.inverse().remove(entry); - this.entryToLifecycle.remove(entry); - this.rawIdToEntry.set(rawId, null); - - this.randomEntries = null; + this.idToEntry.remove(registryEntry); + this.keyToEntry.remove(registryEntry); + this.entryToLifecycle.remove(entry); + this.valueToEntry.remove(entry); + if (this.cachedEntries != null) { + this.cachedEntries.remove(registryEntry); + } + if (this.unfrozenValueToEntry != null) { + this.unfrozenValueToEntry.remove(entry); + } return true; } @Override public boolean remove(Identifier key) { - T entry = this.idToEntry.get(key); - return entry != null && this.remove(entry); + var entry = this.idToEntry.get(key); + return entry != null && entry.hasKeyAndValue() && this.remove(entry.value()); + } + + @Override + public void setFrozen(boolean value) { + this.frozen = value; + } + + @Override + public boolean isFrozen() { + return this.frozen; } } diff --git a/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java b/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java index 130faab..66b87d5 100644 --- a/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java +++ b/src/main/java/xyz/nucleoid/fantasy/util/VoidChunkGenerator.java @@ -1,15 +1,13 @@ package xyz.nucleoid.fantasy.util; import com.mojang.serialization.Codec; +import com.mojang.serialization.Lifecycle; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; import net.minecraft.structure.StructureManager; +import net.minecraft.structure.StructureSet; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.registry.DynamicRegistryManager; -import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.RegistryKey; +import net.minecraft.util.registry.*; import net.minecraft.world.ChunkRegion; import net.minecraft.world.HeightLimitView; import net.minecraft.world.Heightmap; @@ -24,12 +22,11 @@ import net.minecraft.world.gen.StructureAccessor; import net.minecraft.world.gen.chunk.Blender; import net.minecraft.world.gen.chunk.ChunkGenerator; -import net.minecraft.world.gen.chunk.StructuresConfig; import net.minecraft.world.gen.chunk.VerticalBlockSample; -import net.minecraft.world.gen.feature.StructureFeature; -import org.jetbrains.annotations.Nullable; +import net.minecraft.world.gen.densityfunction.DensityFunction; import java.util.Collections; +import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; @@ -44,19 +41,58 @@ public class VoidChunkGenerator extends ChunkGenerator { private static final VerticalBlockSample EMPTY_SAMPLE = new VerticalBlockSample(0, new BlockState[0]); - private final Supplier biome; + private final RegistryEntry biome; - public VoidChunkGenerator(Supplier biome) { - super(new FixedBiomeSource(biome), new StructuresConfig(Optional.empty(), Collections.emptyMap())); + private static final Registry EMPTY_STRUCTURE_REGISTRY = new SimpleRegistry<>(Registry.STRUCTURE_SET_KEY, Lifecycle.stable(), (x) -> null).freeze(); + + public static final DensityFunction ZERO_DENSITY_FUNCTION = new DensityFunction() { + @Override + public double sample(NoisePos pos) { + return 0; + } + + @Override + public void method_40470(double[] ds, class_6911 arg) { } + + @Override + public DensityFunction apply(DensityFunctionVisitor visitor) { + return this; + } + + @Override + public double minValue() { + return 0; + } + + @Override + public double maxValue() { + return 0; + } + + @Override + public Codec getCodec() { + return Codec.unit(this); + } + }; + + public static final MultiNoiseUtil.MultiNoiseSampler EMPTY_SAMPLER = new MultiNoiseUtil.MultiNoiseSampler(ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, ZERO_DENSITY_FUNCTION, Collections.emptyList()); + + public VoidChunkGenerator(RegistryEntry biome) { + super(EMPTY_STRUCTURE_REGISTRY, Optional.empty(), new FixedBiomeSource(biome)); this.biome = biome; } + @Deprecated + public VoidChunkGenerator(Supplier biome) { + this(RegistryEntry.of(biome.get())); + } + public VoidChunkGenerator(Registry biomeRegistry) { this(biomeRegistry, BiomeKeys.THE_VOID); } public VoidChunkGenerator(Registry biomeRegistry, RegistryKey biome) { - this(() -> biomeRegistry.get(biome)); + this(biomeRegistry.getEntry(biome).get()); } @Override @@ -71,9 +107,7 @@ public ChunkGenerator withSeed(long seed) { @Override public MultiNoiseUtil.MultiNoiseSampler getMultiNoiseSampler() { - return (i, j, k) -> { - return MultiNoiseUtil.createNoiseValuePoint(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F); - }; + return EMPTY_SAMPLER; } @Override @@ -127,19 +161,13 @@ public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) return EMPTY_SAMPLE; } - @Nullable @Override - public BlockPos locateStructure(ServerWorld world, StructureFeature feature, BlockPos center, int radius, boolean skipExistingChunks) { - return null; + public void getDebugHudText(List text, BlockPos pos) { + } @Override public void buildSurface(ChunkRegion region, StructureAccessor structures, Chunk chunk) { } - - @Override - public boolean isStrongholdStartingChunk(ChunkPos chunkPos) { - return false; - } } diff --git a/src/main/resources/data/fantasy/dimension_type/default.json b/src/main/resources/data/fantasy/dimension_type/default.json index 22b89c3..8e82889 100644 --- a/src/main/resources/data/fantasy/dimension_type/default.json +++ b/src/main/resources/data/fantasy/dimension_type/default.json @@ -1,6 +1,6 @@ { "logical_height": 256, - "infiniburn": "minecraft:infiniburn_overworld", + "infiniburn": "#minecraft:infiniburn_overworld", "effects": "minecraft:overworld", "ambient_light": 0.0, "respawn_anchor_works": false,