Skip to content

Commit

Permalink
Habitat former (#2270)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedelosk committed Oct 11, 2018
1 parent de62630 commit 1640ca7
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 68 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -5,7 +5,7 @@ curse_project_id=59751

tesla_version=1.0.60
tesla_mcversion=1.12
jei_version=4.10.0.200
jei_version=4.12.1.217
jei_mcversion=1.12.2
ic2_version=2.8.90-ex112
TR_mcversion=1.12.2
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/forestry/apiculture/ModuleApiculture.java
Expand Up @@ -161,6 +161,10 @@ public class ModuleApiculture extends BlankForestryModule {

public static boolean hivesDamageUnderwater = true;

public static boolean hivesDamageOnlyPlayers = false;

public static boolean hiveDamageOnAttack = false;

public static boolean doSelfPollination = true;

public static int maxFlowersSpawnedPerHive = 20;
Expand Down Expand Up @@ -287,6 +291,10 @@ public void doInit() {

hivesDamageUnderwater = config.getBooleanLocalized("beekeeping.hivedamage", "underwater", hivesDamageUnderwater);

hivesDamageOnlyPlayers = config.getBooleanLocalized("beekeeping.hivedamage", "onlyPlayers", hivesDamageOnlyPlayers);

hiveDamageOnAttack = config.getBooleanLocalized("beekeeping.hivedamage", "onlyOnAttack", hiveDamageOnAttack);

doSelfPollination = config.getBooleanLocalized("beekeeping", "self.pollination", false);

config.save();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/forestry/apiculture/tiles/TileHive.java
Expand Up @@ -126,16 +126,15 @@ public void update() {
if (tickHelper.updateOnInterval(angry ? 10 : 200)) {
if (calmTime == 0) {
if (canWork) {
if (world.getWorldInfo().getDifficulty() != EnumDifficulty.PEACEFUL || ModuleApiculture.hivesDamageOnPeaceful) {
if (angry && ModuleApiculture.hiveDamageOnAttack && (world.getWorldInfo().getDifficulty() != EnumDifficulty.PEACEFUL || ModuleApiculture.hivesDamageOnPeaceful)) {
AxisAlignedBB boundingBox = AlleleEffect.getBounding(getContainedBee().getGenome(), this);
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, boundingBox, beeTargetPredicate);
if (!entities.isEmpty()) {
Collections.shuffle(entities);
EntityLivingBase entity = entities.get(0);
if (entity.isInsideOfMaterial(Material.WATER) && !ModuleApiculture.hivesDamageUnderwater) {
return;
if ((entity instanceof EntityPlayer || !ModuleApiculture.hivesDamageOnlyPlayers) && (!entity.isInsideOfMaterial(Material.WATER) || ModuleApiculture.hivesDamageUnderwater)) {
attack(entity, 2);
}
attack(entity, 2);
}
}
beeLogic.doWork();
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/forestry/arboriculture/ModuleArboriculture.java
Expand Up @@ -13,10 +13,12 @@
import com.google.common.base.Preconditions;

import javax.annotation.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Random;
import java.util.Set;

Expand Down Expand Up @@ -52,10 +54,12 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import forestry.Forestry;
import forestry.api.arboriculture.EnumForestryWoodType;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.EnumVanillaWoodType;
import forestry.api.arboriculture.IAlleleFruit;
import forestry.api.arboriculture.IToolGrafter;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.IWoodType;
import forestry.api.arboriculture.TreeManager;
Expand Down Expand Up @@ -84,7 +88,6 @@
import forestry.arboriculture.genetics.TreekeepingMode;
import forestry.arboriculture.genetics.alleles.AlleleFruits;
import forestry.arboriculture.genetics.alleles.AlleleLeafEffects;
import forestry.api.arboriculture.IToolGrafter;
import forestry.arboriculture.items.ItemRegistryArboriculture;
import forestry.arboriculture.models.TextureLeaves;
import forestry.arboriculture.models.WoodTextureManager;
Expand All @@ -99,6 +102,7 @@
import forestry.core.capabilities.NullStorage;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.config.LocalizedConfiguration;
import forestry.core.fluids.Fluids;
import forestry.core.items.ItemFruit.EnumFruit;
import forestry.core.items.ItemRegistryCore;
Expand All @@ -116,6 +120,8 @@
@ForestryModule(containerID = Constants.MOD_ID, moduleID = ForestryModuleUids.ARBORICULTURE, name = "Arboriculture", author = "Binnie & SirSengir", url = Constants.URL, unlocalizedDescription = "for.module.arboriculture.description", lootTable = "arboriculture")
public class ModuleArboriculture extends BlankForestryModule {

private static final String CONFIG_CATEGORY = "arboriculture";

@SuppressWarnings("NullableProblems")
@SidedProxy(clientSide = "forestry.arboriculture.proxy.ProxyArboricultureClient", serverSide = "forestry.arboriculture.proxy.ProxyArboriculture")
public static ProxyArboriculture proxy;
Expand Down Expand Up @@ -265,6 +271,18 @@ public void doInit() {
new VillagerArboristTrades.GivePollenForEmeralds(new EntityVillager.PriceInfo(5, 20), new EntityVillager.PriceInfo(1, 1), EnumGermlingType.SAPLING, 10)
);
}

File configFile = new File(Forestry.instance.getConfigFolder(), CONFIG_CATEGORY + ".cfg");

LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0");
if (!Objects.equals(config.getLoadedConfigVersion(), config.getDefinedConfigVersion())) {
boolean deleted = configFile.delete();
if (deleted) {
config = new LocalizedConfiguration(configFile, "1.0.0");
}
}
TreeConfig.parse(config);
config.save();
}

@Override
Expand Down Expand Up @@ -550,9 +568,10 @@ public boolean processIMCMessage(IMCMessage message) {
}
return true;
} else if (message.key.equals("blacklist-trees-dimension")) {
String treeUID = message.getNBTValue().getString("treeUID");
int[] dims = message.getNBTValue().getIntArray("dimensions");
for(int dim : dims) {
Config.blacklistTreeDim(dim);
TreeConfig.blacklistTreeDim(treeUID, dim);
}
return true;
}
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/forestry/arboriculture/TreeConfig.java
@@ -0,0 +1,111 @@
package forestry.arboriculture;

import javax.annotation.Nullable;
import java.util.HashMap;
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.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.core.config.LocalizedConfiguration;
import forestry.core.utils.Log;

public class TreeConfig {
public static final String CONFIG_CATEGORY_TREE = "trees";
private static final Map<String, TreeConfig> configs = new HashMap<>();
private static final TreeConfig GLOBAL = new TreeConfig("global");

private final String treeName;
private final Set<Integer> blacklistedDimensions = new HashSet<>();
private final Set<Integer> whitelistedDimensions = new HashSet<>();
private final Set<BiomeDictionary.Type> blacklistedBiomeTypes = new HashSet<>();
private final Set<Biome> blacklistedBiomes = new HashSet<>();

public static void parse(LocalizedConfiguration config) {
GLOBAL.parseConfig(config);
for(IAllele treeAllele : AlleleManager.alleleRegistry.getRegisteredAlleles(EnumTreeChromosome.SPECIES)){
if(!(treeAllele instanceof IAlleleTreeSpecies)){
continue;
}
IAlleleTreeSpecies treeSpecies = (IAlleleTreeSpecies) treeAllele;
configs.put(treeSpecies.getUID(), new TreeConfig(treeSpecies.getUID()).parseConfig(config));
}
}

private TreeConfig(String treeName){
this.treeName = treeName;
}

private TreeConfig parseConfig(LocalizedConfiguration config){
for (int dimId : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".dimensions", "blacklist", new int[0]).getIntList()) {
blacklistedDimensions.add(dimId);
}
for (int dimId : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".dimensions", "whitelist", new int[0]).getIntList()) {
whitelistedDimensions.add(dimId);
}
for(String typeName : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".biomes.blacklist", "types", new String[0]).getStringList()){
blacklistedBiomeTypes.add(BiomeDictionary.Type.getType(typeName));
}
for(String biomeName : config.get(CONFIG_CATEGORY_TREE + "." + treeName + ".biomes.blacklist", "names", new String[0]).getStringList()){
Biome biome = ForgeRegistries.BIOMES.getValue(new ResourceLocation(biomeName));
if(biome != null) {
blacklistedBiomes.add(biome);
}else{
Log.error("Failed to identify biome for the config property for the tree with the uid '"+ treeName + "'. No biome is registered under the registry name '"+ biomeName + "'.");
}
}
return this;
}

public static void blacklistTreeDim(@Nullable String treeUID, int dimID) {
TreeConfig treeConfig = configs.get(treeUID);
if(treeUID == null){
treeConfig = GLOBAL;
}
treeConfig.blacklistedDimensions.add(dimID);
}

public static void whitelistTreeDim(@Nullable String treeUID, int dimID) {
TreeConfig treeConfig = configs.get(treeUID);
if(treeUID == null){
treeConfig = GLOBAL;
}
treeConfig.whitelistedDimensions.add(dimID);
}

public static boolean isValidDimension(@Nullable String treeUID, int dimID) {
TreeConfig treeConfig = configs.get(treeUID);
return GLOBAL.isValidDimension(dimID) && (treeConfig == null || treeConfig.isValidDimension(dimID));
}

private boolean isValidDimension(int dimID){ //blacklist has priority
if (blacklistedDimensions.isEmpty() || !blacklistedDimensions.contains(dimID)) {
return whitelistedDimensions.isEmpty() || whitelistedDimensions.contains(dimID);
}
return false;
}

public static boolean isValidBiome(@Nullable String treeUID, Biome biome) {
TreeConfig treeConfig = configs.get(treeUID);
return GLOBAL.isValidBiome(biome) && (treeConfig == null || treeConfig.isValidBiome(biome));
}

private boolean isValidBiome(Biome biome){
if (blacklistedBiomes.contains(biome)) {
return false;
}
return BiomeDictionary.getTypes(biome).stream().noneMatch(blacklistedBiomeTypes::contains);
}

}

24 changes: 8 additions & 16 deletions src/main/java/forestry/arboriculture/worldgen/TreeDecorator.java
Expand Up @@ -39,6 +39,7 @@
import forestry.api.arboriculture.TreeManager;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.TreeConfig;
import forestry.arboriculture.commands.TreeGenHelper;
import forestry.core.config.Config;
import forestry.core.utils.BlockUtil;
Expand All @@ -55,7 +56,7 @@ public void decorateTrees(Decorate event) {
}

public static void decorateTrees(World world, Random rand, int worldX, int worldZ) {
if (!Config.isValidTreeDim(world.provider.getDimension()) || Config.generateTreesAmount == 0) {
if (Config.generateTreesAmount == 0 || !TreeConfig.isValidDimension(null, world.provider.getDimension())) {
return;
}
if (biomeCache.isEmpty()) {
Expand All @@ -67,12 +68,12 @@ public static void decorateTrees(World world, Random rand, int worldX, int world

BlockPos pos = new BlockPos(x, 0, z);
Biome biome = world.getBiome(pos);
if (!Config.isValidTreeBiome(biome)) {
continue;
}

Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
for (ITree tree : trees) {
String treeUID = tree.getGenome().getPrimary().getUID();
if(!TreeConfig.isValidDimension(treeUID, world.provider.getDimension())){
continue;
}
IAlleleTreeSpecies species = tree.getGenome().getPrimary();
if (species.getRarity() * Config.generateTreesAmount >= rand.nextFloat()) {
pos = getValidPos(world, x, z, tree);
Expand Down Expand Up @@ -135,23 +136,14 @@ private static void generateBiomeCache(World world, Random rand) {
IAllele[] template = TreeManager.treeRoot.getTemplate(species);
ITreeGenome genome = TreeManager.treeRoot.templateAsGenome(template);
ITree tree = TreeManager.treeRoot.getTree(world, genome);
String treeUID = genome.getPrimary().getUID();
IGrowthProvider growthProvider = species.getGrowthProvider();
for (Biome biome : Biome.REGISTRY) {
Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
if (growthProvider.isBiomeValid(tree, biome)) {
if (growthProvider.isBiomeValid(tree, biome) && TreeConfig.isValidBiome(treeUID, biome)) {
trees.add(tree);
}
}
}
}

private static final class BiomeCache {
protected final Biome biome;
protected final List<ITree> validTrees;

public BiomeCache(Biome biome, List<ITree> validTrees) {
this.biome = biome;
this.validTrees = validTrees;
}
}
}
43 changes: 0 additions & 43 deletions src/main/java/forestry/core/config/Config.java
Expand Up @@ -93,10 +93,6 @@ public class Config {
public static boolean enableVillagers = true;
public static boolean generateTrees = true;
public static float generateTreesAmount = 1.0F;
public static Set<Integer> blacklistedTreeDims = new HashSet<>();
public static Set<Integer> whitelistedTreeDims = new HashSet<>();
public static Set<BiomeDictionary.Type> blacklistedTreeTypes = new HashSet<>();
public static Set<Biome> blacklistedTreeBiomes = new HashSet<>();

// Retrogen
public static boolean doRetrogen = false;
Expand Down Expand Up @@ -182,14 +178,6 @@ public static boolean isMagicalCropsSupportEnabled() {
return enableMagicalCropsSupport;
}

public static void blacklistTreeDim(int dimID) {
blacklistedTreeDims.add(dimID);
}

public static void whitelistTreeDim(int dimID) {
whitelistedTreeDims.add(dimID);
}

public static void blacklistOreDim(int dimID) {
blacklistedOreDims.add(dimID);
}
Expand All @@ -205,20 +193,6 @@ public static boolean isValidOreDim(int dimID) { //blacklist has priority
return false;
}

public static boolean isValidTreeDim(int dimID) { //blacklist has priority
if (blacklistedTreeDims.isEmpty() || !blacklistedTreeDims.contains(dimID)) {
return whitelistedTreeDims.isEmpty() || whitelistedTreeDims.contains(dimID);
}
return false;
}

public static boolean isValidTreeBiome(Biome biome) {
if (blacklistedTreeBiomes.contains(biome)) {
return false;
}
return !BiomeDictionary.getTypes(biome).stream().anyMatch(blacklistedTreeTypes::contains);
}

public static void load(Side side) {
File configCommonFile = new File(Forestry.instance.getConfigFolder(), CATEGORY_COMMON + ".cfg");
configCommon = new LocalizedConfiguration(configCommonFile, "1.2.1");
Expand Down Expand Up @@ -300,23 +274,6 @@ private static void loadConfigCommon(Side side) {

generateTreesAmount = configCommon.getFloatLocalized("world.generate.trees", "treeFrequency", generateTreesAmount, 0.0F, 10.0F);

for (int dimId : configCommon.get("world.generate.trees", "dimBlacklist", new int[0]).getIntList()) {
blacklistedTreeDims.add(dimId);
}
for (int dimId : configCommon.get("world.generate.trees", "dimWhitelist", new int[0]).getIntList()) {
whitelistedTreeDims.add(dimId);
}
for (String entry : configCommon.get("world.generate.trees", "biomeblacklist", new String[0]).getStringList()) {
BiomeDictionary.Type type = BiomeDictionary.Type.getType(entry);
Biome biome = ForgeRegistries.BIOMES.getValue(new ResourceLocation(entry));
if (type != null) {
blacklistedTreeTypes.add(type);
} else if (biome != null) {
blacklistedTreeBiomes.add(biome);
}
}


craftingBronzeEnabled = configCommon.getBooleanLocalized("crafting", "bronze", craftingBronzeEnabled);
craftingStampsEnabled = configCommon.getBooleanLocalized("crafting.stamps", "enabled", true);

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/forestry/lang/en_us.lang
Expand Up @@ -1834,6 +1834,10 @@ for.config.beekeeping.hivedamage.peaceful=Peaceful Hive Damage
for.config.beekeeping.hivedamage.peaceful.comment=Whether bees can damage a player playing on peaceful mode.
for.config.beekeeping.hivedamage.underwater=Underwater Hive Damage
for.config.beekeeping.hivedamage.underwater.comment=Whether bees can damage a player while they are underwater.
for.config.beekeeping.hivedamage.onlyOnAttack=Defend Hive Damage
for.config.beekeeping.hivedamage.onlyOnAttack.comment=The bees only attack the player if he starts to destroy the hive.
for.config.beekeeping.hivedamage.onlyPlayers=Player Hive Damage
for.config.beekeeping.hivedamage.onlyPlayers.comment=Whether bees can damage other entities than the player.
for.config.beekeeping.self.pollination=Leaf Self Pollination
for.config.beekeeping.self.pollination.comment=If true bees will pollinate leaves with themselves to speed up getting a homozgous genome.
for.config.beekeeping.ignoble.decay=Ignoble Decay
Expand Down

0 comments on commit 1640ca7

Please sign in to comment.