diff --git a/src/main/java/com/xekr/ironstars/mixin/MinecraftMixin.java b/src/main/java/com/xekr/ironstars/mixin/MinecraftMixin.java index a29bf6a..b58eb66 100644 --- a/src/main/java/com/xekr/ironstars/mixin/MinecraftMixin.java +++ b/src/main/java/com/xekr/ironstars/mixin/MinecraftMixin.java @@ -1,7 +1,7 @@ package com.xekr.ironstars.mixin; import com.mojang.serialization.Lifecycle; -import com.xekr.ironstars.world.ModChunkGenerator; +import com.xekr.ironstars.world.MoonChunkGenerator; import net.minecraft.client.Minecraft; import net.minecraft.world.level.storage.WorldData; import net.minecraftforge.api.distmarker.Dist; @@ -17,7 +17,7 @@ public class MinecraftMixin { @Redirect(method = "doLoadLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/WorldData;worldGenSettingsLifecycle()Lcom/mojang/serialization/Lifecycle;")) private Lifecycle isMoonWorld(WorldData instance) { return instance.worldGenSettings().dimensions().entrySet().stream().anyMatch(entry -> - entry.getValue().generator() instanceof ModChunkGenerator + entry.getValue().generator() instanceof MoonChunkGenerator ) ? Lifecycle.stable() : instance.worldGenSettingsLifecycle(); } diff --git a/src/main/java/com/xekr/ironstars/registry/AllDimensions.java b/src/main/java/com/xekr/ironstars/registry/AllDimensions.java index e1758e7..0565dbb 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllDimensions.java +++ b/src/main/java/com/xekr/ironstars/registry/AllDimensions.java @@ -1,16 +1,16 @@ package com.xekr.ironstars.registry; import com.xekr.ironstars.IronStars; -import com.xekr.ironstars.world.BiomeProvider; -import com.xekr.ironstars.world.ModChunkGenerator; +import com.xekr.ironstars.world.MoonBiomeSource; +import com.xekr.ironstars.world.MoonChunkGenerator; import net.minecraft.core.Registry; public class AllDimensions { public static long seed; public static void init() { - Registry.register(Registry.BIOME_SOURCE, IronStars.id("ironstars_biomes"), BiomeProvider.CODEC); + Registry.register(Registry.BIOME_SOURCE, IronStars.id("ironstars_biomes"), MoonBiomeSource.CODEC); - Registry.register(Registry.CHUNK_GENERATOR, IronStars.id("structure_locating_wrapper"), ModChunkGenerator.CODEC); + Registry.register(Registry.CHUNK_GENERATOR, IronStars.id("structure_locating_wrapper"), MoonChunkGenerator.CODEC); } } diff --git a/src/main/java/com/xekr/ironstars/registry/AllEvents.java b/src/main/java/com/xekr/ironstars/registry/AllEvents.java index 5df4cfc..e3dcf77 100644 --- a/src/main/java/com/xekr/ironstars/registry/AllEvents.java +++ b/src/main/java/com/xekr/ironstars/registry/AllEvents.java @@ -2,7 +2,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.xekr.ironstars.command.TestCommand; -import com.xekr.ironstars.world.WorldGenerator; +import com.xekr.ironstars.world.MoonWorldGenerator; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.commands.CommandSourceStack; @@ -30,7 +30,7 @@ static class ModBusGlobal { // mod管线全局事件 public static void gatherData(GatherDataEvent event) { //TODO 不好使 DataGenerator generator = event.getGenerator(); ExistingFileHelper helper = event.getExistingFileHelper(); - generator.addProvider(new WorldGenerator(generator)); + generator.addProvider(new MoonWorldGenerator(generator)); } } @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) diff --git a/src/main/java/com/xekr/ironstars/world/BiomeProvider.java b/src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java similarity index 75% rename from src/main/java/com/xekr/ironstars/world/BiomeProvider.java rename to src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java index f4b7cc4..0107370 100644 --- a/src/main/java/com/xekr/ironstars/world/BiomeProvider.java +++ b/src/main/java/com/xekr/ironstars/world/MoonBiomeSource.java @@ -16,26 +16,21 @@ import java.util.List; import java.util.Optional; -public class BiomeProvider extends BiomeSource { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group( +public class MoonBiomeSource extends BiomeSource { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.LONG.fieldOf("seed").stable().orElseGet(() -> AllDimensions.seed).forGetter(obj -> obj.seed), RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter(provider -> provider.registry) - ).apply(instance, instance.stable(BiomeProvider::new))); + ).apply(instance, instance.stable(MoonBiomeSource::new))); private static final List> BIOMES = ImmutableList.of(Biomes.DESERT); private final Registry registry; private final long seed; - public BiomeProvider(long seed, Registry registryIn) { + public MoonBiomeSource(long seed, Registry registryIn) { super(BIOMES.stream().map(ResourceKey::location).map(registryIn::getOptional).filter(Optional::isPresent).map(opt -> opt::get)); this.seed = seed; - registry = registryIn; - - } - - public static int getBiomeId(ResourceKey biome, Registry registry) { - return registry.getId(registry.get(biome)); + this.registry = registryIn; } @Override @@ -45,7 +40,7 @@ protected Codec codec() { @Override public BiomeSource withSeed(long pSeed) { - return new BiomeProvider(pSeed, registry); + return new MoonBiomeSource(pSeed, this.registry); } @Override diff --git a/src/main/java/com/xekr/ironstars/world/ModChunkGenerator.java b/src/main/java/com/xekr/ironstars/world/MoonChunkGenerator.java similarity index 93% rename from src/main/java/com/xekr/ironstars/world/ModChunkGenerator.java rename to src/main/java/com/xekr/ironstars/world/MoonChunkGenerator.java index 0eebe3d..252368c 100644 --- a/src/main/java/com/xekr/ironstars/world/ModChunkGenerator.java +++ b/src/main/java/com/xekr/ironstars/world/MoonChunkGenerator.java @@ -34,18 +34,18 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; -public class ModChunkGenerator extends ChunkGenerator { - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( +public class MoonChunkGenerator extends ChunkGenerator { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( ChunkGenerator.CODEC.fieldOf("wrapped_generator").forGetter(o -> o.delegate) - ).apply(instance, instance.stable(ModChunkGenerator::new))); + ).apply(instance, instance.stable(MoonChunkGenerator::new))); public final ChunkGenerator delegate; - public ModChunkGenerator(ChunkGenerator delegate, boolean owSeed) { + public MoonChunkGenerator(ChunkGenerator delegate, boolean owSeed) { this(owSeed ? delegate.withSeed(AllDimensions.seed) : delegate); } - private ModChunkGenerator(ChunkGenerator delegate) { + private MoonChunkGenerator(ChunkGenerator delegate) { super(delegate.getBiomeSource(), delegate.getBiomeSource(), delegate.getSettings(), delegate instanceof NoiseBasedChunkGenerator noiseGen ? noiseGen.seed : delegate.strongholdSeed); this.delegate = delegate; } @@ -118,7 +118,7 @@ protected Codec codec() { @Override public ChunkGenerator withSeed(long pSeed) { - return new ModChunkGenerator(this.delegate.withSeed(pSeed)); + return new MoonChunkGenerator(this.delegate.withSeed(pSeed)); } @Override diff --git a/src/main/java/com/xekr/ironstars/world/WorldGenerator.java b/src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java similarity index 94% rename from src/main/java/com/xekr/ironstars/world/WorldGenerator.java rename to src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java index 90e7659..b335cd2 100644 --- a/src/main/java/com/xekr/ironstars/world/WorldGenerator.java +++ b/src/main/java/com/xekr/ironstars/world/MoonWorldGenerator.java @@ -49,13 +49,13 @@ import java.util.OptionalLong; import java.util.function.Supplier; -public class WorldGenerator extends RegistryWriteOps implements DataProvider { +public class MoonWorldGenerator extends RegistryWriteOps implements DataProvider { private final DataGenerator generator; private HashCache cache; private final HashSet SerializeCache = new HashSet<>(); - public WorldGenerator(DataGenerator generator) { + public MoonWorldGenerator(DataGenerator generator) { super(JsonOps.INSTANCE, new RegistryAccess.RegistryHolder()); this.generator = generator; } @@ -208,7 +208,7 @@ private Map getDimensions() { this.getOrCreateInRegistry(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY, IronStars.id("moon_noise_config"), () -> dimensionSettings); - NoiseBasedChunkGenerator chunkGen = new NoiseBasedChunkGenerator(RegistryAccess.builtin().registryOrThrow(Registry.NOISE_REGISTRY), new BiomeProvider(0L, new MappedRegistry<>(Registry.BIOME_REGISTRY, Lifecycle.experimental())), 0L, () -> dimensionSettings); + NoiseBasedChunkGenerator chunkGen = new NoiseBasedChunkGenerator(RegistryAccess.builtin().registryOrThrow(Registry.NOISE_REGISTRY), new MoonBiomeSource(0L, new MappedRegistry<>(Registry.BIOME_REGISTRY, Lifecycle.experimental())), 0L, () -> dimensionSettings); final DimensionType dimensionType = DimensionType.create( OptionalLong.empty(), @@ -233,15 +233,15 @@ private Map getDimensions() { this.getOrCreateInRegistry(Registry.DIMENSION_TYPE_REGISTRY, IronStars.id("moon_type"), () -> dimensionType); return ImmutableMap.of( - IronStars.id("moon"), new LevelStem(() -> dimensionType, new ModChunkGenerator(chunkGen, true)) + IronStars.id("moon"), new LevelStem(() -> dimensionType, new MoonChunkGenerator(chunkGen, true)) ); } public static SurfaceRules.RuleSource tfSurface() { ImmutableList.Builder builder = ImmutableList.builder(); builder.add(SurfaceRules.ifTrue(SurfaceRules.verticalGradient("bedrock_floor", VerticalAnchor.bottom(), VerticalAnchor.aboveBottom(5)), SurfaceRules.state(Blocks.BEDROCK.defaultBlockState()))); - SurfaceRules.RuleSource surfacerules$rulesource9 = SurfaceRules.ifTrue(SurfaceRules.abovePreliminarySurface(), SurfaceRules.state(AllBlocks.MOON_SOIL.get().defaultBlockState())); - builder.add(surfacerules$rulesource9); +// SurfaceRules.RuleSource surfacerules$rulesource9 = SurfaceRules.ifTrue(SurfaceRules.abovePreliminarySurface(), SurfaceRules.state(AllBlocks.MOON_SOIL.get().defaultBlockState())); +// builder.add(surfacerules$rulesource9); return SurfaceRules.sequence(builder.build().toArray(SurfaceRules.RuleSource[]::new)); } } diff --git a/src/main/resources/META-INF/asm/seed.js b/src/main/resources/META-INF/asm/seed.js index 4c1fc43..e736380 100644 --- a/src/main/resources/META-INF/asm/seed.js +++ b/src/main/resources/META-INF/asm/seed.js @@ -1,4 +1,4 @@ -// noinspection ES6ConvertVarToLetConst, JSUnusedGlobalSymbols +// noinspection all var ASM = Java.type('net.minecraftforge.coremod.api.ASMAPI'); var Opcodes = Java.type('org.objectweb.asm.Opcodes');