The bop worldtype now works on servers again

This commit is contained in:
Adubbz 2020-07-08 22:49:29 +10:00
parent 563b2857a4
commit 6a95b28bc6
5 changed files with 101 additions and 8 deletions

View file

@ -14,7 +14,10 @@ import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.DimensionSettings; import net.minecraft.world.gen.DimensionSettings;
import net.minecraft.world.gen.NoiseChunkGenerator; import net.minecraft.world.gen.NoiseChunkGenerator;
import net.minecraft.world.gen.settings.DimensionGeneratorSettings; import net.minecraft.world.gen.settings.DimensionGeneratorSettings;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class BOPBiomeGeneratorTypeScreen extends BiomeGeneratorTypeScreens public class BOPBiomeGeneratorTypeScreen extends BiomeGeneratorTypeScreens
{ {
public BOPBiomeGeneratorTypeScreen() public BOPBiomeGeneratorTypeScreen()
@ -25,12 +28,12 @@ public class BOPBiomeGeneratorTypeScreen extends BiomeGeneratorTypeScreens
@Override @Override
protected ChunkGenerator generator(long seed) protected ChunkGenerator generator(long seed)
{ {
return new NoiseChunkGenerator(new BOPBiomeProvider(seed), seed, DimensionSettings.Preset.OVERWORLD.settings()); return BOPWorldTypeUtil.createChunkGenerator(seed);
} }
@Override @Override
public DimensionGeneratorSettings create(IDynamicRegistries.Impl registries, long seed, boolean generateFeatures, boolean generateBonusChest) public DimensionGeneratorSettings create(IDynamicRegistries.Impl registries, long seed, boolean generateFeatures, boolean generateBonusChest)
{ {
return new DimensionGeneratorSettings(seed, generateFeatures, generateBonusChest, DimensionGeneratorSettings.withOverworld(BOPDimensionType.bopDimensions(seed), this.generator(seed))); return BOPWorldTypeUtil.createDimensionGeneratorSettings(seed, generateFeatures, generateBonusChest);
} }
} }

View file

@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright 2014-2020, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.world;
import biomesoplenty.core.BiomesOPlenty;
import com.google.common.base.MoreObjects;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.dedicated.ServerProperties;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.DimensionSettings;
import net.minecraft.world.gen.NoiseChunkGenerator;
import net.minecraft.world.gen.settings.DimensionGeneratorSettings;
import net.minecraft.world.storage.ServerWorldInfo;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
public class BOPWorldTypeUtil
{
private static boolean isUsingBopWorldType(DedicatedServer server)
{
String levelType = Optional.ofNullable((String)server.getProperties().properties.get("level-type")).map((str) -> str.toLowerCase(Locale.ROOT)).orElse("default");
return levelType.equals("biomesoplenty") || levelType.equals("biomesop");
}
public static ChunkGenerator createChunkGenerator(long seed)
{
return new NoiseChunkGenerator(new BOPBiomeProvider(seed), seed, DimensionSettings.Preset.OVERWORLD.settings());
}
public static DimensionGeneratorSettings createDimensionGeneratorSettings(long seed, boolean generateFeatures, boolean generateBonusChest)
{
return new DimensionGeneratorSettings(seed, generateFeatures, generateBonusChest, DimensionGeneratorSettings.withOverworld(BOPDimensionType.bopDimensions(seed), createChunkGenerator(seed)));
}
public static void setupForDedicatedServer(DedicatedServer server)
{
// Ensure we are using the bop world type
if (!isUsingBopWorldType(server))
return;
ServerProperties properties = server.getProperties();
DimensionGeneratorSettings oldWorldGenSettings = properties.worldGenSettings;
// Obtain the original settings
long seed = oldWorldGenSettings.seed();
boolean generateFeatures = oldWorldGenSettings.generateFeatures();
boolean generateBonusChest = oldWorldGenSettings.generateBonusChest();
BiomesOPlenty.logger.info("Setting world generator settings to biomesoplenty");
DimensionGeneratorSettings newWorldGenSettings = createDimensionGeneratorSettings(seed, generateFeatures, generateBonusChest);
if (server.getWorldData() instanceof ServerWorldInfo)
{
ServerWorldInfo worldInfo = (ServerWorldInfo)server.getWorldData();
worldInfo.worldGenSettings = newWorldGenSettings;
}
// Replace the world gen settings in server.properties
properties.worldGenSettings = newWorldGenSettings;
}
}

View file

@ -8,13 +8,16 @@
package biomesoplenty.core; package biomesoplenty.core;
import biomesoplenty.common.world.BOPWorldTypeUtil;
import biomesoplenty.init.*; import biomesoplenty.init.*;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -37,6 +40,7 @@ public class BiomesOPlenty
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::loadComplete); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::loadComplete);
MinecraftForge.EVENT_BUS.addListener(this::serverStarting);
ModBiomes.setup(); ModBiomes.setup();
ModConfig.setup(); ModConfig.setup();
@ -58,4 +62,15 @@ public class BiomesOPlenty
//GenLayerVisualizer.run(); //GenLayerVisualizer.run();
ModCompatibility.setup(); ModCompatibility.setup();
} }
private void serverStarting(final FMLServerAboutToStartEvent event)
{
// Only apply hackery to dedicated servers
if (!(event.getServer() instanceof DedicatedServer))
{
return;
}
BOPWorldTypeUtil.setupForDedicatedServer((DedicatedServer)event.getServer());
}
} }

View file

@ -23,11 +23,13 @@ import net.minecraft.entity.villager.IVillagerType;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biomes;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type; import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.loading.FMLEnvironment;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -44,8 +46,11 @@ public class ModBiomes
public static void setup() public static void setup()
{ {
biomeGeneratorTypeScreenBOP = new BOPBiomeGeneratorTypeScreen(); if (FMLEnvironment.dist == Dist.CLIENT)
BiomeGeneratorTypeScreens.PRESETS.add(biomeGeneratorTypeScreenBOP); {
biomeGeneratorTypeScreenBOP = new BOPBiomeGeneratorTypeScreen();
BiomeGeneratorTypeScreens.PRESETS.add(biomeGeneratorTypeScreenBOP);
}
// Register biome providers // Register biome providers
Registry.register(Registry.BIOME_SOURCE, "biomesoplenty_overworld", BOPBiomeProvider.CODEC); Registry.register(Registry.BIOME_SOURCE, "biomesoplenty_overworld", BOPBiomeProvider.CODEC);

View file

@ -5,6 +5,11 @@ public-f net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens *
public net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens <init>(Ljava/lang/String;)V public net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens <init>(Ljava/lang/String;)V
public net.minecraft.block.Blocks *() public net.minecraft.block.Blocks *()
# server.properties world type hackery
public-f net.minecraft.server.dedicated.ServerProperties *
public-f net.minecraft.world.storage.ServerWorldInfo *
public net.minecraft.server.dedicated.PropertyManager *
# Make various Block related things public # Make various Block related things public
public net.minecraft.block.Block$Properties *() public net.minecraft.block.Block$Properties *()
@ -20,8 +25,4 @@ public net.minecraft.block.PressurePlateBlock <init>(Lnet/minecraft/block/Pressu
public-f net.minecraft.item.AxeItem field_203176_a # BLOCK_STRIPPING_MAP public-f net.minecraft.item.AxeItem field_203176_a # BLOCK_STRIPPING_MAP
# server.properties world type hackery
public-f net.minecraft.server.dedicated.ServerProperties *
public net.minecraft.server.dedicated.PropertyManager *
protected net.minecraft.entity.item.BoatEntity func_184447_s()V #tickLerp protected net.minecraft.entity.item.BoatEntity func_184447_s()V #tickLerp