Skip to content

Commit

Permalink
Merge pull request #88 from Cjsah/1.18
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Cjsah authored Jan 25, 2022
2 parents 8d87a96 + 2d014f1 commit 1f4c883
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/xekr/ironstars/mixin/MinecraftMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/xekr/ironstars/registry/AllDimensions.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/xekr/ironstars/registry/AllEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,21 @@
import java.util.List;
import java.util.Optional;

public class BiomeProvider extends BiomeSource {
public static final Codec<BiomeProvider> CODEC = RecordCodecBuilder.create((instance) -> instance.group(
public class MoonBiomeSource extends BiomeSource {
public static final Codec<MoonBiomeSource> 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<ResourceKey<Biome>> BIOMES = ImmutableList.of(Biomes.DESERT);

private final Registry<Biome> registry;
private final long seed;

public BiomeProvider(long seed, Registry<Biome> registryIn) {
public MoonBiomeSource(long seed, Registry<Biome> 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> biome, Registry<Biome> registry) {
return registry.getId(registry.get(biome));
this.registry = registryIn;
}

@Override
Expand All @@ -45,7 +40,7 @@ protected Codec<? extends BiomeSource> codec() {

@Override
public BiomeSource withSeed(long pSeed) {
return new BiomeProvider(pSeed, registry);
return new MoonBiomeSource(pSeed, this.registry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

public class ModChunkGenerator extends ChunkGenerator {
public static final Codec<ModChunkGenerator> CODEC = RecordCodecBuilder.create(instance -> instance.group(
public class MoonChunkGenerator extends ChunkGenerator {
public static final Codec<MoonChunkGenerator> 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;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ protected Codec<? extends ChunkGenerator> codec() {

@Override
public ChunkGenerator withSeed(long pSeed) {
return new ModChunkGenerator(this.delegate.withSeed(pSeed));
return new MoonChunkGenerator(this.delegate.withSeed(pSeed));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
import java.util.OptionalLong;
import java.util.function.Supplier;

public class WorldGenerator extends RegistryWriteOps<JsonElement> implements DataProvider {
public class MoonWorldGenerator extends RegistryWriteOps<JsonElement> implements DataProvider {
private final DataGenerator generator;

private HashCache cache;
private final HashSet<Object> SerializeCache = new HashSet<>();

public WorldGenerator(DataGenerator generator) {
public MoonWorldGenerator(DataGenerator generator) {
super(JsonOps.INSTANCE, new RegistryAccess.RegistryHolder());
this.generator = generator;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private Map<ResourceLocation, LevelStem> 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(),
Expand All @@ -233,15 +233,15 @@ private Map<ResourceLocation, LevelStem> 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<SurfaceRules.RuleSource> 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));
}
}
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/asm/seed.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down

0 comments on commit 1f4c883

Please sign in to comment.