mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 20:42:35 +00:00
Fix #1399 Add Hive Generation Blacklist
This commit is contained in:
1 parent
850a7e2919
commit
644145ac92
5 files changed
+84
-10
No files matched your search
@@ -8,9 +8,10 @@ package forestry.api.apiculture.hives;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import forestry.api.apiculture.IHiveDrop;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import forestry.api.apiculture.IHiveDrop;
|
||||
|
||||
public interface IHiveRegistry {
|
||||
|
||||
/* Forestry Hive Names */
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package forestry.apiculture;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
import forestry.api.apiculture.hives.IHiveRegistry;
|
||||
import forestry.core.config.LocalizedConfiguration;
|
||||
|
||||
public class HiveConfig {
|
||||
private static final Map<IHiveRegistry.HiveType, HiveConfig> configs = new EnumMap<IHiveRegistry.HiveType, HiveConfig>(IHiveRegistry.HiveType.class);
|
||||
private static final String CATEGORY = "world.generate.beehives.blacklist";
|
||||
|
||||
private final Set<BiomeDictionary.Type> blacklistedTypes = new HashSet<>();
|
||||
private final Set<Biome> blacklistedBiomes = new HashSet<>();
|
||||
|
||||
public static void parse(LocalizedConfiguration config){
|
||||
config.addCategoryCommentLocalized(CATEGORY);
|
||||
for(IHiveRegistry.HiveType type : IHiveRegistry.HiveType.values()){
|
||||
String[] entries = config.get(CATEGORY, type.getName(), new String[0]).getStringList();
|
||||
configs.put(type, new HiveConfig(entries));
|
||||
}
|
||||
}
|
||||
|
||||
public HiveConfig(String[] entries){
|
||||
for(String entry : entries){
|
||||
BiomeDictionary.Type type = BiomeDictionary.Type.getType(entry);
|
||||
Biome biome = ForgeRegistries.BIOMES.getValue(new ResourceLocation(entry));
|
||||
if(type != null){
|
||||
blacklistedTypes.add(type);
|
||||
}else if(biome != null){
|
||||
blacklistedBiomes.add(biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBlacklisted(IHiveRegistry.HiveType type, Biome biome){
|
||||
HiveConfig config = configs.get(type);
|
||||
if(config == null){
|
||||
return false;
|
||||
}
|
||||
return config.isBlacklisted(biome);
|
||||
}
|
||||
|
||||
private boolean isBlacklisted(Biome biome){
|
||||
if(blacklistedBiomes.contains(biome)){
|
||||
return true;
|
||||
}
|
||||
return BiomeDictionary.getTypes(biome).stream().anyMatch(blacklistedTypes::contains);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,15 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.hives.HiveManager;
|
||||
import forestry.api.apiculture.hives.IHiveDescription;
|
||||
@@ -25,16 +34,10 @@ import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumTolerance;
|
||||
import forestry.apiculture.HiveConfig;
|
||||
import forestry.apiculture.ModuleApiculture;
|
||||
import forestry.apiculture.genetics.BeeDefinition;
|
||||
import forestry.core.config.Constants;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
public enum HiveDescription implements IHiveDescription {
|
||||
|
||||
@@ -102,12 +105,14 @@ public enum HiveDescription implements IHiveDescription {
|
||||
private final float genChance;
|
||||
private final IBeeGenome beeGenome;
|
||||
private final IHiveGen hiveGen;
|
||||
private final IHiveRegistry.HiveType hiveType;
|
||||
|
||||
HiveDescription(IHiveRegistry.HiveType hiveType, float genChance, BeeDefinition beeTemplate, IHiveGen hiveGen) {
|
||||
this.blockState = ModuleApiculture.getBlocks().beehives.getStateForType(hiveType);
|
||||
this.genChance = genChance;
|
||||
this.beeGenome = beeTemplate.getGenome();
|
||||
this.hiveGen = hiveGen;
|
||||
this.hiveType = hiveType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,7 +127,7 @@ public enum HiveDescription implements IHiveDescription {
|
||||
|
||||
@Override
|
||||
public boolean isGoodBiome(Biome biome) {
|
||||
return !BiomeHelper.isBiomeHellish(biome);
|
||||
return !BiomeHelper.isBiomeHellish(biome) && !HiveConfig.isBlacklisted(hiveType, biome);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
import forestry.Forestry;
|
||||
import forestry.apiculture.HiveConfig;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
@@ -212,6 +213,8 @@ public class Config {
|
||||
generateBeehivesAmount = configCommon.getFloatLocalized("world.generate.beehives", "amount", generateBeehivesAmount, 0.0f, 10.0f);
|
||||
generateBeehivesDebug = configCommon.getBooleanLocalized("world.generate.beehives", "debug", generateBeehivesDebug);
|
||||
|
||||
HiveConfig.parse(configCommon);
|
||||
|
||||
generateApatiteOre = configCommon.getBooleanLocalized("world.generate.ore", "apatite", generateApatiteOre);
|
||||
generateCopperOre = configCommon.getBooleanLocalized("world.generate.ore", "copper", generateCopperOre);
|
||||
generateTinOre = configCommon.getBooleanLocalized("world.generate.ore", "tin", generateTinOre);
|
||||
|
||||
@@ -13,10 +13,11 @@ package forestry.core.config;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public class LocalizedConfiguration extends Configuration {
|
||||
|
||||
public LocalizedConfiguration(File file, String configVersion) {
|
||||
@@ -146,4 +147,9 @@ public class LocalizedConfiguration extends Configuration {
|
||||
return getInt(name, category, defaultValue, minValue, maxValue, comment, langKey);
|
||||
}
|
||||
|
||||
public void addCategoryCommentLocalized(String category){
|
||||
String langKey = "for.config." + category + '.' + "category_comment";
|
||||
setCategoryComment(category, Translator.translateToLocal(langKey));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user