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.
This commit is contained in:
Sebastian Hartte
2020-09-05 19:15:45 +02:00
parent c8a5049d71
commit 689bf6e8d9
7 changed files with 86 additions and 214 deletions
+35 -29
View File
@@ -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<String> 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<String> getMeteoriteDimensionWhitelist() {
return this.meteoriteDimensionWhitelist;
public List<String> getMeteoriteBiomeBlacklist() {
return commonConfig.meteoriteBiomeBlacklist.get();
}
// Setters keep visibility as low as possible.
public List<String> 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<PowerUnits> 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<IntegerOption> craftByStacks;
public final List<IntegerOption> priorityByStacks;
public final List<IntegerOption> 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<String> 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);
-24
View File
@@ -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() {
+51 -21
View File
@@ -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<String> meteoriteBiomeBlacklist = new HashSet<>(AEConfig.instance().getMeteoriteBiomeBlacklist());
Set<String> quartzOreBiomeBlacklist = new HashSet<>(AEConfig.instance().getQuartzOreBiomeBlacklist());
// Add features to all existing biomes
for (Map.Entry<RegistryKey<Biome>, 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;
}
@@ -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;
@@ -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 <http://www.gnu.org/licenses/lgpl>.
*/
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<Identifier> badDimensions = new HashSet<>();
final HashSet<Identifier> enabledDimensions = new HashSet<>();
}
}