From 2375a2b7fc6059948a5b529f14a0d72cffbd157a Mon Sep 17 00:00:00 2001 From: dags- Date: Wed, 1 Apr 2020 09:21:57 +0100 Subject: [PATCH] - fix logic for loading generator settings - start support on external datapack support - add command to save the current TF worlds gen settings as defaults - support mushroom fields as a beach biome - register custom arg types to support command completion on servers --- .../com/terraforged/mod/TerraForgedMod.java | 17 +++++++++++++ .../java/com/terraforged/mod/TerraWorld.java | 12 ++++++---- .../mod/biome/map/BiomePredicate.java | 2 +- .../mod/biome/provider/BiomeHelper.java | 12 ++++------ .../terraforged/mod/command/TerraCommand.java | 11 +++++++-- .../mod/command/arg/BiomeArgType.java | 2 +- .../mod/settings/SettingsHelper.java | 24 ++++++++++--------- .../terraforged/mod/util/DataPackFinder.java | 22 +++++++++++++++++ 8 files changed, 75 insertions(+), 27 deletions(-) create mode 100644 TerraForgedMod/src/main/java/com/terraforged/mod/util/DataPackFinder.java diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java index cdbd6fe..5e24a1e 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraForgedMod.java @@ -27,9 +27,11 @@ package com.terraforged.mod; import com.terraforged.api.material.WGTags; import com.terraforged.feature.FeatureManager; +import com.terraforged.mod.command.TerraCommand; import com.terraforged.mod.data.DataGen; import com.terraforged.mod.feature.feature.DiskFeature; import com.terraforged.mod.feature.tree.SaplingManager; +import com.terraforged.mod.util.DataPackFinder; import com.terraforged.mod.util.Environment; import net.minecraft.world.biome.Biomes; import net.minecraft.world.gen.feature.Feature; @@ -39,6 +41,9 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent; + +import java.io.File; /** * Author @@ -53,6 +58,7 @@ public class TerraForgedMod { WGTags.init(); TerraWorld.init(); SaplingManager.init(); + TerraCommand.init(); // temp fix BiomeDictionary.addTypes(Biomes.BAMBOO_JUNGLE, BiomeDictionary.Type.OVERWORLD); @@ -71,4 +77,15 @@ public class TerraForgedMod { FeatureManager.registerTemplates(event); event.getRegistry().register(DiskFeature.INSTANCE); } + + @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) + public static class ForgeEvents { + @SubscribeEvent + public static void serverStart(FMLServerAboutToStartEvent event) { + Log.info("Adding DataPackFinder"); + File dir = event.getServer().getFile("config/terraforged/datapacks"); + DataPackFinder dataPackFinder = new DataPackFinder(dir); + event.getServer().getResourcePacks().addPackFinder(dataPackFinder); + } + } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java index 3f49c4b..260e032 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/TerraWorld.java @@ -35,6 +35,7 @@ import com.terraforged.mod.chunk.test.TestChunkGenerator; import com.terraforged.mod.gui.SettingsScreen; import com.terraforged.mod.settings.SettingsHelper; import com.terraforged.mod.settings.TerraSettings; +import com.terraforged.mod.util.Environment; import com.terraforged.mod.util.nbt.NBTHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.CreateWorldScreen; @@ -52,11 +53,9 @@ import java.util.HashSet; import java.util.Set; public class TerraWorld extends WorldType { - public static final int VERSION = 1; + public static final int VERSION = 1; private static final Set types = new HashSet<>(); - public static final TerraWorld TERRA = new TerraWorld("terraforged", TerraChunkGenerator::new); - public static final TerraWorld TEST = new TerraWorld("terratest", TestChunkGenerator::new); private final ChunkGeneratorFactory factory; @@ -113,7 +112,12 @@ public class TerraWorld extends WorldType { } public static void init() { - Log.info("Registered world type(s)"); + Log.info("Registered world type"); + new TerraWorld("terraforged", TerraChunkGenerator::new); + if (Environment.isDev()) { + Log.info("Registered developer world type"); + new TerraWorld("terratest", TestChunkGenerator::new); + } } public static boolean isTerraWorld(IWorld world) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java index 8b58fcd..30e3fcd 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/map/BiomePredicate.java @@ -84,7 +84,7 @@ public interface BiomePredicate { return false; } - BiomePredicate COAST = type(Biome.Category.BEACH); + BiomePredicate COAST = type(Biome.Category.BEACH, Biome.Category.MUSHROOM).or(name("shore")).or(name("beach")); BiomePredicate WETLAND = type(Biome.Category.SWAMP); BiomePredicate DESERT = type(Biome.Category.DESERT).or(temp(0.9, 2).and(rain(-1, 0.2))); BiomePredicate SAVANNA = type(Biome.Category.SAVANNA).or(temp(0.8, 2).and(rain(-1, 0.4))); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java index 406bbaf..f36058c 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/biome/provider/BiomeHelper.java @@ -87,23 +87,19 @@ public class BiomeHelper { weight = 5; } - if (biome.getCategory() == Biome.Category.MUSHROOM) { - weight = 1; - } - // don't use BiomeDictionary with transient biomes if (ForgeRegistries.BIOMES.containsKey(biome.getRegistryName())) { if (BiomeDictionary.getTypes(biome).contains(BiomeDictionary.Type.RARE)) { - weight = 1; + weight = 2; } } - if (biome.getCategory() == Biome.Category.OCEAN) { + if (BiomePredicate.COAST.test(data)) { + builder.addBeach(biome, weight); + } else if (biome.getCategory() == Biome.Category.OCEAN) { builder.addOcean(biome, weight); } else if (biome.getCategory() == Biome.Category.RIVER) { builder.addRiver(biome, weight); - } else if (biome.getCategory() == Biome.Category.BEACH || biome == Biomes.STONE_SHORE) { - builder.addBeach(biome, weight); } else if (biome.getCategory() == Biome.Category.SWAMP) { builder.addWetland(biome, weight); } else { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java index 5cc5d7c..50800e8 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/command/TerraCommand.java @@ -49,6 +49,8 @@ import com.terraforged.mod.data.DataGen; import com.terraforged.mod.settings.SettingsHelper; import net.minecraft.command.CommandSource; import net.minecraft.command.Commands; +import net.minecraft.command.arguments.ArgumentSerializer; +import net.minecraft.command.arguments.ArgumentTypes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.server.MinecraftServer; @@ -77,8 +79,13 @@ import java.util.function.Supplier; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) public class TerraCommand { + public static void init() { + ArgumentTypes.register("terraforged:biome", BiomeArgType.class, new ArgumentSerializer<>(BiomeArgType::new)); + ArgumentTypes.register("terraforged:terrain", TerrainArgType.class, new ArgumentSerializer<>(TerrainArgType::new)); + } + @SubscribeEvent - public static void start(FMLServerStartingEvent event) { + public static void register(FMLServerStartingEvent event) { Log.info("Registering /terra command"); register(event.getCommandDispatcher()); } @@ -165,7 +172,7 @@ public class TerraCommand { context.getSource().sendFeedback(new StringTextComponent( "Actual Biome = " + actual.getRegistryName() - + "\nLookup Biome = " + biome2.getRegistryName()), + + "\nLookup Biome = " + biome2.getRegistryName()), false ); diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java b/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java index 10a3b54..0dfc4a5 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/command/arg/BiomeArgType.java @@ -52,7 +52,7 @@ public class BiomeArgType implements ArgumentType { @Override public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder suggestions) { - return ISuggestionProvider.func_212476_a(ForgeRegistries.BIOMES.getValues().stream().map(Biome::getRegistryName), suggestions); + return ISuggestionProvider.suggestIterable(ForgeRegistries.BIOMES.getKeys(), suggestions); } private static CommandSyntaxException createException(String type, String message, Object... args) { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java index 35f4a0d..a80a4dd 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/settings/SettingsHelper.java @@ -74,18 +74,20 @@ public class SettingsHelper { } public static TerraSettings getSettings(IWorld world) { - try (Reader reader = new BufferedReader(new FileReader(new File("config", SETTINGS_FILE_NAME)))) { - Log.info("Loading generator settings from json"); - return new Gson().fromJson(reader, TerraSettings.class); - } catch (Throwable ignored) { - return getSettings(world.getWorldInfo()); - } - } - - public static TerraSettings getSettings(WorldInfo info) { TerraSettings settings = new TerraSettings(); - if (!info.getGeneratorOptions().isEmpty()) { - NBTHelper.deserialize(info.getGeneratorOptions(), settings); + if (world.getWorldInfo().getGeneratorOptions().isEmpty()) { + File defaults = new File("config", SETTINGS_FILE_NAME); + if (defaults.exists()) { + try (Reader reader = new BufferedReader(new FileReader(defaults))) { + Log.info("Loading generator settings from json"); + return new Gson().fromJson(reader, TerraSettings.class); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } else { + Log.info("Loading generator settings from level.dat"); + NBTHelper.deserialize(world.getWorldInfo().getGeneratorOptions(), settings); } return settings; } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/util/DataPackFinder.java b/TerraForgedMod/src/main/java/com/terraforged/mod/util/DataPackFinder.java new file mode 100644 index 0000000..c74602e --- /dev/null +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/util/DataPackFinder.java @@ -0,0 +1,22 @@ +package com.terraforged.mod.util; + +import com.terraforged.mod.Log; +import net.minecraft.resources.FolderPackFinder; +import net.minecraft.resources.ResourcePackInfo; + +import java.io.File; +import java.util.Map; + +public class DataPackFinder extends FolderPackFinder { + + public DataPackFinder(File folderIn) { + super(folderIn); + } + + @Override + public void addPackInfosToMap(Map map, ResourcePackInfo.IFactory factory) { + int start = map.size(); + super.addPackInfosToMap(map, factory); + Log.info("Found {} datapacks", map.size() - start); + } +}