- 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
This commit is contained in:
dags- 2020-04-01 09:21:57 +01:00
parent 69be3a17f6
commit 2375a2b7fc
8 changed files with 75 additions and 27 deletions

View File

@ -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 <dags@dags.me>
@ -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);
}
}
}

View File

@ -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<WorldType> 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) {

View File

@ -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)));

View File

@ -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 {

View File

@ -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
);

View File

@ -52,7 +52,7 @@ public class BiomeArgType implements ArgumentType<Biome> {
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> 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) {

View File

@ -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;
}

View File

@ -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 <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> map, ResourcePackInfo.IFactory<T> factory) {
int start = map.size();
super.addPackInfosToMap(map, factory);
Log.info("Found {} datapacks", map.size() - start);
}
}