Skip to content

Commit

Permalink
Fix new world creation on servers
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorrell committed Feb 16, 2022
1 parent dde25bb commit 125394c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 77 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1G

# Mod Properties
mod_version=3.1.1
mod_version=3.1.2
archives_base_name=skyblock

# Fabric Properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,73 @@
package com.jsorrell.skyblock.gen;

import com.mojang.serialization.Lifecycle;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.MultiNoiseBiomeSource;
import net.minecraft.world.biome.source.TheEndBiomeSource;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;

public class SkyBlockGenerationSettings {

public static final String NAME = "skyblock";

public static SimpleRegistry<DimensionOptions> getSkyBlockDimensionOptions(
Registry<DimensionType> dimensionTypeRegistry,
Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry,
Registry<ChunkGeneratorSettings> settingsRegistry,
public static SimpleRegistry<DimensionOptions> getSkyBlockDimensionOptionsRegistry(
DynamicRegistryManager drm,
long seed) {
SimpleRegistry<DimensionOptions> simpleRegistry =
new SimpleRegistry<>(Registry.DIMENSION_KEY, Lifecycle.experimental());
simpleRegistry.add(
SimpleRegistry<DimensionOptions> dimensionOptionsRegistry = new SimpleRegistry<>(Registry.DIMENSION_KEY, Lifecycle.experimental());

Registry<DimensionType> dimensionTypeRegistry = drm.get(Registry.DIMENSION_TYPE_KEY);

dimensionOptionsRegistry.add(
DimensionOptions.OVERWORLD,
new DimensionOptions(
() -> dimensionTypeRegistry.get(DimensionType.OVERWORLD_REGISTRY_KEY),
createOverworldGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed)),
() -> dimensionTypeRegistry.getOrThrow(DimensionType.OVERWORLD_REGISTRY_KEY),
createOverworldGenerator(drm, seed)),
Lifecycle.stable());
simpleRegistry.add(

dimensionOptionsRegistry.add(
DimensionOptions.NETHER,
new DimensionOptions(
() -> dimensionTypeRegistry.get(DimensionType.THE_NETHER_REGISTRY_KEY),
createNetherGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed)),
() -> dimensionTypeRegistry.getOrThrow(DimensionType.THE_NETHER_REGISTRY_KEY),
createNetherGenerator(drm, seed)),
Lifecycle.stable());
simpleRegistry.add(

dimensionOptionsRegistry.add(
DimensionOptions.END,
new DimensionOptions(
() -> dimensionTypeRegistry.get(DimensionType.THE_END_REGISTRY_KEY),
createEndGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed)),
() -> dimensionTypeRegistry.getOrThrow(DimensionType.THE_END_REGISTRY_KEY),
createEndGenerator(drm, seed)),
Lifecycle.stable());
return simpleRegistry;
return dimensionOptionsRegistry;
}

public static ChunkGenerator createOverworldGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
public static SkyBlockChunkGenerator createOverworldGenerator(DynamicRegistryManager drm, long seed) {
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = drm.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
return new SkyBlockChunkGenerator(
noiseRegistry,
MultiNoiseBiomeSource.Preset.OVERWORLD.getBiomeSource(biomeRegistry).withSeed(seed),
drm.get(Registry.NOISE_WORLDGEN),
MultiNoiseBiomeSource.Preset.OVERWORLD.getBiomeSource(drm.get(Registry.BIOME_KEY), true),
seed,
() -> settingsRegistry.getOrThrow(ChunkGeneratorSettings.OVERWORLD));
() -> chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.OVERWORLD));
}

public static ChunkGenerator createNetherGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
public static SkyBlockChunkGenerator createNetherGenerator(DynamicRegistryManager drm, long seed) {
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = drm.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
return new SkyBlockChunkGenerator(
noiseRegistry,
MultiNoiseBiomeSource.Preset.NETHER.getBiomeSource(biomeRegistry).withSeed(seed),
drm.get(Registry.NOISE_WORLDGEN),
MultiNoiseBiomeSource.Preset.NETHER.getBiomeSource(drm.get(Registry.BIOME_KEY)).withSeed(seed),
seed,
() -> settingsRegistry.getOrThrow(ChunkGeneratorSettings.NETHER));
() -> chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.NETHER));
}

public static ChunkGenerator createEndGenerator(Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry,
Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> settingsRegistry, long seed) {
public static SkyBlockChunkGenerator createEndGenerator(DynamicRegistryManager drm, long seed) {
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = drm.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
return new SkyBlockChunkGenerator(
noiseRegistry,
new TheEndBiomeSource(biomeRegistry, seed),
drm.get(Registry.NOISE_WORLDGEN),
new TheEndBiomeSource(drm.get(Registry.BIOME_KEY), seed),
seed,
() -> settingsRegistry.getOrThrow(ChunkGeneratorSettings.END));
() -> chunkGeneratorSettingsRegistry.getOrThrow(ChunkGeneratorSettings.END));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,30 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;

@Environment(EnvType.CLIENT)
public class SkyBlockGeneratorTypes {
public static final GeneratorType SKYBLOCK =
new GeneratorType("skyblock") {
@Override
protected ChunkGenerator getChunkGenerator(DynamicRegistryManager registryManager, long seed) {
Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry = registryManager.get(Registry.NOISE_WORLDGEN);
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
Registry<ChunkGeneratorSettings> settingsRegistry =
registryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);
return SkyBlockGenerationSettings.createOverworldGenerator(noiseRegistry, biomeRegistry, settingsRegistry, seed);
protected ChunkGenerator getChunkGenerator(DynamicRegistryManager drm, long seed) {
return SkyBlockGenerationSettings.createOverworldGenerator(drm, seed);
}

@Override
public GeneratorOptions createDefaultOptions(
DynamicRegistryManager.Impl registryManager,
DynamicRegistryManager.Impl drm,
long seed,
boolean generateStructures,
boolean bonusChest) {
Registry<DimensionType> dimensionTypeRegistry =
registryManager.get(Registry.DIMENSION_TYPE_KEY);
Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseRegistry = registryManager.get(Registry.NOISE_WORLDGEN);
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
Registry<ChunkGeneratorSettings> settingsRegistry =
registryManager.get(Registry.CHUNK_GENERATOR_SETTINGS_KEY);

SimpleRegistry<DimensionOptions> dimensionOptionsRegistry =
SkyBlockGenerationSettings.getSkyBlockDimensionOptions(
dimensionTypeRegistry, noiseRegistry, biomeRegistry, settingsRegistry, seed);
return new GeneratorOptions(
seed, generateStructures, bonusChest, dimensionOptionsRegistry);
seed,
generateStructures,
bonusChest,
SkyBlockGenerationSettings.getSkyBlockDimensionOptionsRegistry(drm, seed));
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

import com.jsorrell.skyblock.gen.SkyBlockGenerationSettings;
import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.GeneratorOptions;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -34,17 +28,16 @@ private static void addSkyBlockGeneratorOptionWhenLoadingProperties(
boolean generateStructures,
String string4,
String generatorSettingsName,
long seed,
Registry<DimensionType> dimensionTypeRegistry,
Registry<Biome> biomeRegistry,
SimpleRegistry<ChunkGeneratorSettings> settingsRegistry) {
long seed
) {
if (SkyBlockGenerationSettings.NAME.equals(generatorSettingsName)) {
SimpleRegistry<DimensionOptions> dimensionOptions =
SkyBlockGenerationSettings.getSkyBlockDimensionOptions(
dimensionTypeRegistry, drm.get(Registry.NOISE_WORLDGEN), biomeRegistry, settingsRegistry, seed);
GeneratorOptions generatorOptions =
new GeneratorOptions(seed, generateStructures, false, dimensionOptions);
cir.setReturnValue(generatorOptions);
GeneratorOptions x = new GeneratorOptions(
seed,
generateStructures,
false,
SkyBlockGenerationSettings.getSkyBlockDimensionOptionsRegistry(drm, seed)
);
cir.setReturnValue(x);
}
}
}

0 comments on commit 125394c

Please sign in to comment.