From 689bf6e8d95a51e9e0e0b47f04cdde6c6600413c Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Sat, 5 Sep 2020 19:15:45 +0200 Subject: [PATCH] Removed unused worldgen registry, added biome blacklists for meteorites and quartz ore, and also fixed adding meteorite/quartz to biomes that are registered after AE2 initializes. --- .../api/features/IRegistryContainer.java | 5 -- .../java/appeng/api/features/IWorldGen.java | 40 --------- src/main/java/appeng/core/AEConfig.java | 64 +++++++------ src/main/java/appeng/core/AppEngBase.java | 24 ----- .../java/appeng/core/AppEngBootstrap.java | 72 ++++++++++----- .../registries/RegistryContainer.java | 6 -- .../features/registries/WorldGenRegistry.java | 89 ------------------- 7 files changed, 86 insertions(+), 214 deletions(-) delete mode 100644 src/api/java/appeng/api/features/IWorldGen.java delete mode 100644 src/main/java/appeng/core/features/registries/WorldGenRegistry.java diff --git a/src/api/java/appeng/api/features/IRegistryContainer.java b/src/api/java/appeng/api/features/IRegistryContainer.java index 0819f8123..5a97a0870 100644 --- a/src/api/java/appeng/api/features/IRegistryContainer.java +++ b/src/api/java/appeng/api/features/IRegistryContainer.java @@ -82,11 +82,6 @@ public interface IRegistryContainer { */ IPlayerRegistry players(); - /** - * get access to the world-gen api. - */ - IWorldGen worldgen(); - /** * Register your IPart models before using them. */ diff --git a/src/api/java/appeng/api/features/IWorldGen.java b/src/api/java/appeng/api/features/IWorldGen.java deleted file mode 100644 index ced2d43ea..000000000 --- a/src/api/java/appeng/api/features/IWorldGen.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package appeng.api.features; - -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.Identifier; - -public interface IWorldGen { - - void enableWorldGenForDimension(WorldGenType type, Identifier dimID); - - void disableWorldGenForDimension(WorldGenType type, Identifier dimID); - - boolean isWorldGenEnabled(WorldGenType type, ServerWorld w); - - enum WorldGenType { - CERTUS_QUARTZ, CHARGED_CERTUS_QUARTZ, METEORITES - } -} diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 079924817..67c2bbf82 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -18,22 +18,6 @@ package appeng.core; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.DoubleSupplier; -import java.util.stream.Collectors; - -import net.minecraft.world.dimension.DimensionType; - import appeng.api.config.CondenserOutput; import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerUnits; @@ -53,6 +37,18 @@ import appeng.core.config.StringListOption; import appeng.core.settings.TickRates; import appeng.util.EnumCycler; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.DoubleSupplier; +import java.util.stream.Collectors; + public final class AEConfig { public final ClientConfig clientConfig; @@ -74,13 +70,20 @@ public final class AEConfig { } private static ConfigFileManager createConfigFileManager(ConfigSection commonRoot, File configDir, - String filename) { + String filename) { File configFile = new File(configDir, filename); ConfigFileManager result = new ConfigFileManager(commonRoot, configFile); if (!configFile.exists()) { result.save(); // Save a default file } else { result.load(); + + // Re-save immediately to write-out new defaults + try { + result.save(); + } catch (Exception e) { + AELog.warn(e); + } } return result; } @@ -117,7 +120,7 @@ public final class AEConfig { private final int[] craftByStacks = new int[4]; private final int[] priorityByStacks = new int[4]; private final int[] levelByStacks = new int[4]; - private final int[] levelByMillibuckets = { 10, 100, 1000, 10000 }; + private final int[] levelByMillibuckets = {10, 100, 1000, 10000}; // Spatial IO/Dimension private double spatialPowerExponent; @@ -137,7 +140,6 @@ public final class AEConfig { // Meteors private int meteoriteMaximumSpawnHeight; - private Set meteoriteDimensionWhitelist; // Wireless private double wirelessBaseCost; @@ -175,7 +177,6 @@ public final class AEConfig { this.oreDoublePercentage = (float) commonConfig.oreDoublePercentage.get(); this.meteoriteMaximumSpawnHeight = commonConfig.meteoriteMaximumSpawnHeight.get(); - this.meteoriteDimensionWhitelist = new HashSet<>(commonConfig.meteoriteDimensionWhitelist.get()); this.wirelessBaseCost = commonConfig.wirelessBaseCost.get(); this.wirelessCostMultiplier = commonConfig.wirelessCostMultiplier.get(); @@ -389,11 +390,15 @@ public final class AEConfig { return this.meteoriteMaximumSpawnHeight; } - public Set getMeteoriteDimensionWhitelist() { - return this.meteoriteDimensionWhitelist; + public List getMeteoriteBiomeBlacklist() { + return commonConfig.meteoriteBiomeBlacklist.get(); } - // Setters keep visibility as low as possible. + public List getQuartzOreBiomeBlacklist() { + return commonConfig.quartzOreBiomeBlacklist.get(); + } + +// Setters keep visibility as low as possible. private static class ClientConfig { @@ -405,7 +410,7 @@ public final class AEConfig { public final EnumOption selectedPowerUnit; // GUI Buttons - private static final int[] BTN_BY_STACK_DEFAULTS = { 1, 10, 100, 1000 }; + private static final int[] BTN_BY_STACK_DEFAULTS = {1, 10, 100, 1000}; public final List craftByStacks; public final List priorityByStacks; public final List levelByStacks; @@ -478,10 +483,11 @@ public final class AEConfig { public final DoubleOption spawnChargedChance; public final IntegerOption quartzOresPerCluster; public final IntegerOption quartzOresClusterAmount; + public final StringListOption quartzOreBiomeBlacklist; // Meteors public final IntegerOption meteoriteMaximumSpawnHeight; - public final StringListOption meteoriteDimensionWhitelist; + public final StringListOption meteoriteBiomeBlacklist; // Wireless public final DoubleOption wirelessBaseCost; @@ -562,13 +568,13 @@ public final class AEConfig { this.spawnChargedChance = worldGen.addDouble("spawnChargedChance", 0.08, 0.0, 1.0); this.meteoriteMaximumSpawnHeight = worldGen.addInt("meteoriteMaximumSpawnHeight", 180); - List defaultDimensionWhitelist = new ArrayList<>(); - defaultDimensionWhitelist.add(DimensionType.OVERWORLD_REGISTRY_KEY.getValue().toString()); - this.meteoriteDimensionWhitelist = worldGen.addStringList("meteoriteDimensionWhitelist", - defaultDimensionWhitelist); + this.meteoriteBiomeBlacklist = worldGen.addStringList("meteoriteBiomeBlacklist", new ArrayList<>(), + "Biome IDs in which meteorites should NOT be generated (i.e. minecraft:plains)."); this.quartzOresPerCluster = worldGen.addInt("quartzOresPerCluster", 4); this.quartzOresClusterAmount = worldGen.addInt("quartzOresClusterAmount", 20); + this.quartzOreBiomeBlacklist = worldGen.addStringList("quartzOreBiomeBlacklist", new ArrayList<>(), + "Biome IDs in which quartz ores should NOT be generated (i.e. minecraft:plains)."); ConfigSection wireless = root.subsection("wireless"); this.wirelessBaseCost = wireless.addDouble("wirelessBaseCost", 8.0); diff --git a/src/main/java/appeng/core/AppEngBase.java b/src/main/java/appeng/core/AppEngBase.java index b92ee4cc8..54c620a8d 100644 --- a/src/main/java/appeng/core/AppEngBase.java +++ b/src/main/java/appeng/core/AppEngBase.java @@ -30,14 +30,8 @@ import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.screen.ScreenHandlerType; -import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; -import net.minecraft.world.dimension.DimensionType; - -import team.reborn.energy.Energy; -import team.reborn.energy.EnergyHandler; -import team.reborn.energy.EnergyHolder; import appeng.api.config.Upgrades; import appeng.api.definitions.IBlocks; @@ -45,8 +39,6 @@ import appeng.api.definitions.IItems; import appeng.api.definitions.IParts; import appeng.api.features.IRegistryContainer; import appeng.api.features.IWirelessTermHandler; -import appeng.api.features.IWorldGen; -import appeng.api.implementations.items.IAEItemPowerStorage; import appeng.api.movable.IMovableRegistry; import appeng.api.networking.IGridCacheRegistry; import appeng.api.networking.crafting.ICraftingGrid; @@ -57,7 +49,6 @@ import appeng.api.networking.spatial.ISpatialCache; import appeng.api.networking.storage.IStorageGrid; import appeng.api.networking.ticking.ITickManager; import appeng.api.parts.CableRenderMode; -import appeng.block.AEBaseBlockItemChargeable; import appeng.bootstrap.IBootstrapComponent; import appeng.bootstrap.components.ITileEntityRegistrationComponent; import appeng.client.render.effects.ParticleTypes; @@ -351,21 +342,6 @@ public abstract class AppEngBase implements AppEng { */ mr.whiteListBlockEntity(AEBaseBlockEntity.class); - /* - * world gen - */ - for (final IWorldGen.WorldGenType type : IWorldGen.WorldGenType.values()) { - // FIXME: registries.worldgen().disableWorldGenForProviderID( type, - // StorageWorldProvider.class ); - - registries.worldgen().disableWorldGenForDimension(type, DimensionType.THE_NETHER_REGISTRY_KEY.getValue()); - } - - // whitelist from config - for (final String dimension : AEConfig.instance().getMeteoriteDimensionWhitelist()) { - registries.worldgen().enableWorldGenForDimension(IWorldGen.WorldGenType.METEORITES, - new Identifier(dimension)); - } } protected void registerParticleTypes() { diff --git a/src/main/java/appeng/core/AppEngBootstrap.java b/src/main/java/appeng/core/AppEngBootstrap.java index 1e94f2862..5ffe4c087 100644 --- a/src/main/java/appeng/core/AppEngBootstrap.java +++ b/src/main/java/appeng/core/AppEngBootstrap.java @@ -1,18 +1,5 @@ package appeng.core; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.block.BlockState; -import net.minecraft.util.registry.BuiltinRegistries; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.GenerationStep; -import net.minecraft.world.gen.decorator.Decorator; -import net.minecraft.world.gen.decorator.NopeDecoratorConfig; -import net.minecraft.world.gen.decorator.RangeDecoratorConfig; -import net.minecraft.world.gen.feature.ConfiguredFeature; -import net.minecraft.world.gen.feature.Feature; -import net.minecraft.world.gen.feature.OreFeatureConfig; - import appeng.api.features.AEFeature; import appeng.mixins.feature.ConfiguredFeaturesAccessor; import appeng.mixins.structure.ConfiguredStructureFeaturesAccessor; @@ -24,6 +11,25 @@ import appeng.worldgen.ChargedQuartzOreConfig; import appeng.worldgen.ChargedQuartzOreFeature; import appeng.worldgen.meteorite.MeteoriteStructure; import appeng.worldgen.meteorite.MeteoriteStructurePiece; +import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.block.BlockState; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BuiltinRegistries; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.decorator.Decorator; +import net.minecraft.world.gen.decorator.NopeDecoratorConfig; +import net.minecraft.world.gen.decorator.RangeDecoratorConfig; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.OreFeatureConfig; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** * Hooks into the very early bootstrapping phase to register things before the @@ -54,11 +60,29 @@ public final class AppEngBootstrap { ConfiguredFeature quartzOreFeature = registerQuartzOreFeature(); ConfiguredFeature chargedQuartzOreFeature = registerChargedQuartzOreFeature(); - // add to all standard biomes - // TODO: This means we'll not add these things to newly created biomes - BuiltinRegistries.BIOME.forEach(b -> { - addMeteoriteWorldGen(b); - addQuartzWorldGen(b, quartzOreFeature, chargedQuartzOreFeature); + Set meteoriteBiomeBlacklist = new HashSet<>(AEConfig.instance().getMeteoriteBiomeBlacklist()); + Set quartzOreBiomeBlacklist = new HashSet<>(AEConfig.instance().getQuartzOreBiomeBlacklist()); + + // Add features to all existing biomes + for (Map.Entry, Biome> entry : BuiltinRegistries.BIOME.getEntries()) { + Identifier id = entry.getKey().getValue(); + Biome b = entry.getValue(); + if (!meteoriteBiomeBlacklist.contains(id.toString())) { + addMeteoriteWorldGen(id, b); + } + if (!quartzOreBiomeBlacklist.contains(id.toString())) { + addQuartzWorldGen(id, b, quartzOreFeature, chargedQuartzOreFeature); + } + } + + // Listen to added biomes for post-processing + RegistryEntryAddedCallback.event(BuiltinRegistries.BIOME).register((i, id, biome) -> { + if (!meteoriteBiomeBlacklist.contains(id.toString())) { + addMeteoriteWorldGen(id, biome); + } + if (!quartzOreBiomeBlacklist.contains(id.toString())) { + addQuartzWorldGen(id, biome, quartzOreFeature, chargedQuartzOreFeature); + } }); registerDimension(); @@ -78,7 +102,7 @@ public final class AppEngBootstrap { MeteoriteStructure.CONFIGURED_INSTANCE); } - private static void addMeteoriteWorldGen(Biome b) { + private static void addMeteoriteWorldGen(Identifier id, Biome b) { if (!AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) { return; } @@ -91,9 +115,15 @@ public final class AppEngBootstrap { modifier.addStructureFeature(MeteoriteStructure.CONFIGURED_INSTANCE); } - private static void addQuartzWorldGen(Biome b, ConfiguredFeature quartzOre, - ConfiguredFeature chargedQuartz) { + private static void addQuartzWorldGen(Identifier id, Biome b, ConfiguredFeature quartzOre, + ConfiguredFeature chargedQuartz) { if (!AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) { + AELog.debug("Not generating quartz-ore in %s because the feature is disabled", id); + return; + } + + if (b.getCategory() == Biome.Category.THEEND || b.getCategory() == Biome.Category.NETHER) { + AELog.debug("Not generating quartz ore in %s because it's of category %s", id, b.getCategory()); return; } diff --git a/src/main/java/appeng/core/features/registries/RegistryContainer.java b/src/main/java/appeng/core/features/registries/RegistryContainer.java index 93646e311..e36e1cd71 100644 --- a/src/main/java/appeng/core/features/registries/RegistryContainer.java +++ b/src/main/java/appeng/core/features/registries/RegistryContainer.java @@ -25,7 +25,6 @@ import appeng.api.features.IP2PTunnelRegistry; import appeng.api.features.IPlayerRegistry; import appeng.api.features.IRegistryContainer; import appeng.api.features.IWirelessTermRegistry; -import appeng.api.features.IWorldGen; import appeng.api.movable.IMovableRegistry; import appeng.api.networking.IGridCacheRegistry; import appeng.api.parts.IPartModels; @@ -99,11 +98,6 @@ public class RegistryContainer implements IRegistryContainer { return this.playerRegistry; } - @Override - public IWorldGen worldgen() { - return WorldGenRegistry.INSTANCE; - } - @Override public IPartModels partModels() { return this.partModels; diff --git a/src/main/java/appeng/core/features/registries/WorldGenRegistry.java b/src/main/java/appeng/core/features/registries/WorldGenRegistry.java deleted file mode 100644 index a5995fa5e..000000000 --- a/src/main/java/appeng/core/features/registries/WorldGenRegistry.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.core.features.registries; - -import java.util.HashSet; - -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.Identifier; - -import appeng.api.features.IWorldGen; - -public final class WorldGenRegistry implements IWorldGen { - - public static final WorldGenRegistry INSTANCE = new WorldGenRegistry(); - private final TypeSet[] types; - - private WorldGenRegistry() { - - this.types = new TypeSet[WorldGenType.values().length]; - - for (final WorldGenType type : WorldGenType.values()) { - this.types[type.ordinal()] = new TypeSet(); - } - } - - @Override - public void enableWorldGenForDimension(final WorldGenType type, final Identifier dimensionID) { - if (type == null) { - throw new IllegalArgumentException("Bad Type Passed"); - } - - this.types[type.ordinal()].enabledDimensions.add(dimensionID); - } - - @Override - public void disableWorldGenForDimension(final WorldGenType type, final Identifier dimensionID) { - if (type == null) { - throw new IllegalArgumentException("Bad Type Passed"); - } - - this.types[type.ordinal()].badDimensions.add(dimensionID); - } - - @Override - public boolean isWorldGenEnabled(final WorldGenType type, final ServerWorld w) { - if (type == null) { - throw new IllegalArgumentException("Bad Type Passed"); - } - - if (w == null) { - throw new IllegalArgumentException("Bad Provider Passed"); - } - - Identifier id = w.getRegistryKey().getValue(); - final boolean isBadDimension = this.types[type.ordinal()].badDimensions.contains(id); - final boolean isGoodDimension = this.types[type.ordinal()].enabledDimensions.contains(id); - - if (isBadDimension) { - return false; - } - - if (!isGoodDimension && type == WorldGenType.METEORITES) { - return false; - } - - return true; - } - - private static class TypeSet { - final HashSet badDimensions = new HashSet<>(); - final HashSet enabledDimensions = new HashSet<>(); - } -}