diff --git a/gradle.properties b/gradle.properties index c74f66293..6f7b5c5fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ ic2_version=2.5.5-ex19 version_major=5 version_minor=1 -version_patch=2 +version_patch=3 diff --git a/lang b/lang index 9be86d3c9..a5a5f41bd 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 9be86d3c990b38cb1af259865a4ec243261ecd36 +Subproject commit a5a5f41bd786899e97669e08fab256cc954e2009 diff --git a/src/main/java/forestry/api/arboriculture/EnumForestryWoodType.java b/src/main/java/forestry/api/arboriculture/EnumForestryWoodType.java index b2bde961e..a790625d7 100644 --- a/src/main/java/forestry/api/arboriculture/EnumForestryWoodType.java +++ b/src/main/java/forestry/api/arboriculture/EnumForestryWoodType.java @@ -10,28 +10,53 @@ import java.util.Locale; import java.util.Random; public enum EnumForestryWoodType implements IWoodType { - LARCH, TEAK, ACACIA, LIME, - CHESTNUT, WENGE, BAOBAB, SEQUOIA(4.0f), + LARCH(4, 20), + TEAK(4, 20), + ACACIA(4, 20), + LIME(4, 19), + CHESTNUT(4, 21), + WENGE(4, 20), + BAOBAB(4, 20), + SEQUOIA(3, 18, 4.0f), - KAPOK, EBONY, MAHOGANY, BALSA(1.0f), - WILLOW, WALNUT, GREENHEART(7.5f), CHERRY, + KAPOK(4, 20), + EBONY(4, 20), + MAHOGANY(4, 20), + BALSA(4, 20, 1.0f), + WILLOW(4, 20), + WALNUT(4, 21), + GREENHEART(4, 20, 7.5f), + CHERRY(4, 20), - MAHOE, POPLAR, PALM, PAPAYA, - PINE(3.0f), PLUM, MAPLE, CITRUS, + MAHOE(4, 20), + POPLAR(4, 20), + PALM(4, 20), + PAPAYA(4, 20), + PINE(4, 20, 3.0f), + PLUM(4, 20), + MAPLE(4, 20), + CITRUS(4, 20), - GIGANTEUM, IPE, PADAUK, COCOBOLO, - ZEBRAWOOD; + GIGANTEUM(3, 18, 4.0f), + IPE(4, 20), + PADAUK(4, 20), + COCOBOLO(4, 20), + ZEBRAWOOD(4, 20); public static final float DEFAULT_HARDNESS = 2.0f; public static final EnumForestryWoodType[] VALUES = values(); + private final int carbonization; + private final int combustability; private final float hardness; - EnumForestryWoodType() { - this(DEFAULT_HARDNESS); + EnumForestryWoodType(int carbonization, int combustability) { + this(carbonization, combustability, DEFAULT_HARDNESS); } - EnumForestryWoodType(float hardness) { + EnumForestryWoodType(int carbonization, int combustability, float hardness) { + this.carbonization = carbonization; + this.combustability = combustability; this.hardness = hardness; } @@ -66,4 +91,12 @@ public enum EnumForestryWoodType implements IWoodType { } return VALUES[meta]; } + + public int getCarbonization() { + return carbonization; + } + + public int getCombustability() { + return combustability; + } } diff --git a/src/main/java/forestry/api/arboriculture/EnumTreeChromosome.java b/src/main/java/forestry/api/arboriculture/EnumTreeChromosome.java index eac831086..80d55f94d 100644 --- a/src/main/java/forestry/api/arboriculture/EnumTreeChromosome.java +++ b/src/main/java/forestry/api/arboriculture/EnumTreeChromosome.java @@ -7,8 +7,6 @@ package forestry.api.arboriculture; import java.util.Locale; -import net.minecraftforge.common.EnumPlantType; - import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleArea; import forestry.api.genetics.IAlleleBoolean; @@ -18,6 +16,7 @@ import forestry.api.genetics.IAllelePlantType; import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IFruitFamily; import forestry.api.genetics.ISpeciesRoot; +import net.minecraftforge.common.EnumPlantType; public enum EnumTreeChromosome implements IChromosomeType { @@ -28,7 +27,9 @@ public enum EnumTreeChromosome implements IChromosomeType { SPECIES(IAlleleTreeSpecies.class), /** * {@link IGrowthProvider}, determines conditions required by the tree to grow. + * @deprecated unused */ + @Deprecated GROWTH(IAlleleGrowth.class), /** * A float modifying the height of the tree. Taken into account at worldgen. @@ -48,15 +49,19 @@ public enum EnumTreeChromosome implements IChromosomeType { YIELD(IAlleleFloat.class), /** * May add additional tolerances for {@link EnumPlantType}. + * @deprecated this is tied to species directly */ + @Deprecated PLANT(IAllelePlantType.class), /** * Determines the speed at which fruit will ripen on this tree. */ SAPPINESS(IAlleleFloat.class), /** - * Territory for leaf effects. Unused. + * Territory for leaf effects. + * @deprecated unused */ + @Deprecated TERRITORY(IAlleleArea.class), /** * Leaf effect. Unused. @@ -70,11 +75,15 @@ public enum EnumTreeChromosome implements IChromosomeType { GIRTH(IAlleleInteger.class), /** * The combustibility of the wood, when it burn to charcoal and the combustibility of the charcoal. + * @deprecated this is tied to species directly */ + @Deprecated COMBUSTIBILITY(IAlleleInteger.class), /** * The amount of charcoal that a wood pile ash drop; + * @deprecated this is tied to species directly */ + @Deprecated CARBONIZATION(IAlleleInteger.class), /** * Determines if the tree can burn. diff --git a/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java b/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java index 8bd368907..4e34dfaef 100644 --- a/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java +++ b/src/main/java/forestry/api/arboriculture/EnumVanillaWoodType.java @@ -7,12 +7,12 @@ import java.util.Random; import net.minecraft.block.BlockPlanks; public enum EnumVanillaWoodType implements IWoodType { - OAK(BlockPlanks.EnumType.OAK), - SPRUCE(BlockPlanks.EnumType.SPRUCE), - BIRCH(BlockPlanks.EnumType.BIRCH), - JUNGLE(BlockPlanks.EnumType.JUNGLE), - ACACIA(BlockPlanks.EnumType.ACACIA), - DARK_OAK(BlockPlanks.EnumType.DARK_OAK); + OAK(BlockPlanks.EnumType.OAK, 5, 20), + SPRUCE(BlockPlanks.EnumType.SPRUCE, 4, 19), + BIRCH(BlockPlanks.EnumType.BIRCH, 4, 19), + JUNGLE(BlockPlanks.EnumType.JUNGLE, 5, 20), + ACACIA(BlockPlanks.EnumType.ACACIA, 4, 20), + DARK_OAK(BlockPlanks.EnumType.DARK_OAK, 5, 20); public static final EnumVanillaWoodType[] VALUES = values(); @@ -21,9 +21,13 @@ public enum EnumVanillaWoodType implements IWoodType { } private final BlockPlanks.EnumType vanillaType; + private final int carbonization; + private final int combustability; - EnumVanillaWoodType(BlockPlanks.EnumType vanillaType) { + EnumVanillaWoodType(BlockPlanks.EnumType vanillaType, int carbonization, int combustability) { this.vanillaType = vanillaType; + this.carbonization = carbonization; + this.combustability = combustability; } public BlockPlanks.EnumType getVanillaType() { @@ -57,4 +61,14 @@ public enum EnumVanillaWoodType implements IWoodType { public float getHardness() { return 2.0F; } + + @Override + public int getCarbonization() { + return carbonization; + } + + @Override + public int getCombustability() { + return combustability; + } } diff --git a/src/main/java/forestry/api/arboriculture/IGrowthProvider.java b/src/main/java/forestry/api/arboriculture/IGrowthProvider.java index a54ec6555..c6591d647 100644 --- a/src/main/java/forestry/api/arboriculture/IGrowthProvider.java +++ b/src/main/java/forestry/api/arboriculture/IGrowthProvider.java @@ -10,6 +10,10 @@ import javax.annotation.Nullable; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +/** + * @deprecated this is being removed to simplify trees + */ +@Deprecated public interface IGrowthProvider { /** @@ -25,8 +29,6 @@ public interface IGrowthProvider { @Nullable BlockPos canGrow(ITreeGenome genome, World world, BlockPos pos, int expectedGirth, int expectedHeight); - EnumGrowthConditions getGrowthConditions(ITreeGenome genome, World world, BlockPos pos); - /** * @return Short, human-readable identifier used in the treealyzer. */ diff --git a/src/main/java/forestry/api/arboriculture/ITree.java b/src/main/java/forestry/api/arboriculture/ITree.java index 7a3c1b873..1204a9ede 100644 --- a/src/main/java/forestry/api/arboriculture/ITree.java +++ b/src/main/java/forestry/api/arboriculture/ITree.java @@ -7,24 +7,19 @@ package forestry.api.arboriculture; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.EnumSet; import java.util.List; import java.util.Map; +import com.mojang.authlib.GameProfile; +import forestry.api.genetics.IEffectData; +import forestry.api.genetics.IIndividual; +import forestry.api.world.ITreeGenData; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraft.world.gen.feature.WorldGenerator; -import com.mojang.authlib.GameProfile; - -import net.minecraftforge.common.EnumPlantType; - -import forestry.api.genetics.IEffectData; -import forestry.api.genetics.IIndividual; -import forestry.api.world.ITreeGenData; - public interface ITree extends IIndividual, ITreeGenData { void mate(ITree other); @@ -39,8 +34,6 @@ public interface ITree extends IIndividual, ITreeGenData { ITreeGenome getMate(); - EnumSet getPlantTypes(); - /** * @since Forestry 4.0 */ @@ -86,11 +79,6 @@ public interface ITree extends IIndividual, ITreeGenData { @Override int getGirth(); - /** - * @return Growth conditions at the given position. - */ - EnumGrowthConditions getGrowthCondition(World world, BlockPos pos); - WorldGenerator getTreeGenerator(World world, BlockPos pos, boolean wasBonemealed); @Override diff --git a/src/main/java/forestry/api/arboriculture/ITreeGenome.java b/src/main/java/forestry/api/arboriculture/ITreeGenome.java index cf938a193..2dacfe15a 100644 --- a/src/main/java/forestry/api/arboriculture/ITreeGenome.java +++ b/src/main/java/forestry/api/arboriculture/ITreeGenome.java @@ -6,9 +6,6 @@ package forestry.api.arboriculture; import javax.annotation.Nonnull; -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; import forestry.api.genetics.IGenome; @@ -23,8 +20,6 @@ public interface ITreeGenome extends IGenome { @Nonnull IFruitProvider getFruitProvider(); - IGrowthProvider getGrowthProvider(); - float getHeight(); float getFertility(); @@ -37,18 +32,12 @@ public interface ITreeGenome extends IGenome { float getSappiness(); - EnumSet getPlantTypes(); - /** * @return Amount of random block ticks required for a sapling to mature into a fully grown tree. */ int getMaturationTime(); int getGirth(); - - int getCombustibility(); - - int getCarbonization(); IAlleleLeafEffect getEffect(); } diff --git a/src/main/java/forestry/api/arboriculture/IWoodProvider.java b/src/main/java/forestry/api/arboriculture/IWoodProvider.java index 3451ce6d4..fe4fd8c3a 100644 --- a/src/main/java/forestry/api/arboriculture/IWoodProvider.java +++ b/src/main/java/forestry/api/arboriculture/IWoodProvider.java @@ -7,12 +7,12 @@ package forestry.api.arboriculture; import javax.annotation.Nonnull; +import forestry.api.core.ITextureManager; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.api.core.ITextureManager; public interface IWoodProvider { @SideOnly(Side.CLIENT) @@ -30,4 +30,14 @@ public interface IWoodProvider { * @return A stack of wood from the tree to craft wood pile's or other things. */ ItemStack getWoodStack(); + + /** + * @return how long this wood's charcoal burns / 1000 + */ + int getCombustibility(); + + /** + * The amount of charcoal dropped from a charcoal pile of this wood. + */ + int getCarbonization(); } diff --git a/src/main/java/forestry/api/arboriculture/IWoodType.java b/src/main/java/forestry/api/arboriculture/IWoodType.java index 9352073e6..972c3b19c 100644 --- a/src/main/java/forestry/api/arboriculture/IWoodType.java +++ b/src/main/java/forestry/api/arboriculture/IWoodType.java @@ -10,4 +10,8 @@ public interface IWoodType extends IStringSerializable { int getMetadata(); float getHardness(); + + int getCarbonization(); + + int getCombustability(); } diff --git a/src/main/java/forestry/api/genetics/ICheckPollinatable.java b/src/main/java/forestry/api/genetics/ICheckPollinatable.java index 01f2f409f..28d062969 100644 --- a/src/main/java/forestry/api/genetics/ICheckPollinatable.java +++ b/src/main/java/forestry/api/genetics/ICheckPollinatable.java @@ -10,11 +10,8 @@ ******************************************************************************/ package forestry.api.genetics; -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.arboriculture.ITree; +import net.minecraftforge.common.EnumPlantType; /** * Used to check for pollination traits without altering the world by changing vanilla leaves to forestry ones. @@ -23,10 +20,10 @@ import forestry.api.arboriculture.ITree; public interface ICheckPollinatable { /** - * @return plant types this pollinatable is classified as. + * @return plant type this pollinatable is classified as. * (Can be used by bees to determine whether to interact or not.) */ - EnumSet getPlantType(); + EnumPlantType getPlantType(); /** * @return IIndividual containing the genetic information of this IPollinatable diff --git a/src/main/java/forestry/api/genetics/ISpeciesRoot.java b/src/main/java/forestry/api/genetics/ISpeciesRoot.java index 5e9e2d9ac..4ea27083a 100644 --- a/src/main/java/forestry/api/genetics/ISpeciesRoot.java +++ b/src/main/java/forestry/api/genetics/ISpeciesRoot.java @@ -12,12 +12,11 @@ import java.util.List; import java.util.Map; import java.util.Random; +import com.mojang.authlib.GameProfile; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import com.mojang.authlib.GameProfile; - /** * Describes a class of species (i.e. bees, trees, butterflies), provides helper functions and access to common functionality. */ @@ -105,9 +104,9 @@ public interface ISpeciesRoot { void registerTemplate(String identifier, IAllele[] template); /** - * Retrieves a registered template using the passed identifier. + * Retrieves a registered template using the passed species unique identifier. * - * @param identifier + * @param identifier species UID * @return Array of {@link IAllele} representing a genome. */ IAllele[] getTemplate(String identifier); @@ -170,14 +169,14 @@ public interface ISpeciesRoot { void setResearchSuitability(ItemStack itemstack, float suitability); /** - * @return Array of {@link IChromosomeType} which are in this species genome + * @return Array of all {@link IChromosomeType} which are in this species genome */ IChromosomeType[] getKaryotype(); /** - * @return {@link IChromosomeType} which is the "key" for this species class, usually the species chromosome. + * @return {@link IChromosomeType} which is the "key" for this species class, the species chromosome. */ - IChromosomeType getKaryotypeKey(); + IChromosomeType getSpeciesChromosomeType(); /** * Plugin to add information for the handheld genetic analyzer. diff --git a/src/main/java/forestry/api/multiblock/ICharcoalPileComponent.java b/src/main/java/forestry/api/multiblock/ICharcoalPileComponent.java index 672f309bd..0f0ab76c3 100644 --- a/src/main/java/forestry/api/multiblock/ICharcoalPileComponent.java +++ b/src/main/java/forestry/api/multiblock/ICharcoalPileComponent.java @@ -8,9 +8,8 @@ package forestry.api.multiblock; import javax.annotation.Nonnull; import com.mojang.authlib.GameProfile; - import forestry.api.arboriculture.EnumPileType; -import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.IAlleleTreeSpecies; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -23,11 +22,10 @@ public interface ICharcoalPileComponent @Override T getMultiblockLogic(); - - @Nonnull - ITree getTree(); - - void setTree(@Nonnull ITree tree); + + IAlleleTreeSpecies getTreeSpecies(); + + void setTreeSpecies(@Nonnull IAlleleTreeSpecies treeSpecies); @Override @Nonnull @@ -38,6 +36,6 @@ public interface ICharcoalPileComponent EnumPileType getPileType(); @SideOnly(Side.CLIENT) - ITree getNextWoodPile(); + IAlleleTreeSpecies getNextWoodPile(); } \ No newline at end of file diff --git a/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java b/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java index 81ec30799..2260874e9 100644 --- a/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java +++ b/src/main/java/forestry/apiculture/compat/ApicultureJeiPlugin.java @@ -5,16 +5,15 @@ import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; -import net.minecraft.item.ItemStack; - +import forestry.api.apiculture.BeeManager; import forestry.api.genetics.IAlleleSpecies; import forestry.apiculture.PluginApiculture; -import forestry.apiculture.genetics.BeeGenome; - +import forestry.core.genetics.Genome; import mezz.jei.api.BlankModPlugin; import mezz.jei.api.IModRegistry; import mezz.jei.api.ISubtypeRegistry; import mezz.jei.api.JEIPlugin; +import net.minecraft.item.ItemStack; @JEIPlugin public class ApicultureJeiPlugin extends BlankModPlugin { @@ -51,7 +50,7 @@ public class ApicultureJeiPlugin extends BlankModPlugin { @Nullable @Override public String getSubtypeInfo(@Nonnull ItemStack itemStack) { - IAlleleSpecies species = BeeGenome.getSpeciesDirectly(itemStack); + IAlleleSpecies species = Genome.getSpeciesDirectly(BeeManager.beeRoot, itemStack); return species == null ? null : species.getUID(); } } diff --git a/src/main/java/forestry/apiculture/flowers/FlowerProvider.java b/src/main/java/forestry/apiculture/flowers/FlowerProvider.java index d8f390743..a9a4cb72a 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerProvider.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerProvider.java @@ -10,19 +10,15 @@ ******************************************************************************/ package forestry.apiculture.flowers; -import java.util.EnumSet; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.apiculture.FlowerManager; import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.core.utils.Translator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.EnumPlantType; public class FlowerProvider implements IFlowerProvider { @@ -42,15 +38,15 @@ public class FlowerProvider implements IFlowerProvider { @Override public boolean isAcceptedPollinatable(World world, ICheckPollinatable pollinatable) { - EnumSet plantTypes = pollinatable.getPlantType(); + EnumPlantType plantType = pollinatable.getPlantType(); switch (flowerType) { case FlowerManager.FlowerTypeNether: - return plantTypes.contains(EnumPlantType.Nether); + return plantType == EnumPlantType.Nether; case FlowerManager.FlowerTypeCacti: - return plantTypes.contains(EnumPlantType.Desert); + return plantType == EnumPlantType.Desert; default: - return plantTypes.size() > 1 || !plantTypes.contains(EnumPlantType.Nether); + return plantType != EnumPlantType.Nether; } } diff --git a/src/main/java/forestry/apiculture/genetics/BeeGenome.java b/src/main/java/forestry/apiculture/genetics/BeeGenome.java index 2494f87b9..46c002e65 100755 --- a/src/main/java/forestry/apiculture/genetics/BeeGenome.java +++ b/src/main/java/forestry/apiculture/genetics/BeeGenome.java @@ -10,17 +10,12 @@ ******************************************************************************/ package forestry.apiculture.genetics; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; - import javax.annotation.Nonnull; import java.util.concurrent.TimeUnit; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.Vec3i; - +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.IAlleleBeeEffect; @@ -38,6 +33,9 @@ import forestry.core.genetics.Genome; import forestry.core.genetics.alleles.AlleleArea; import forestry.core.genetics.alleles.AlleleBoolean; import forestry.core.genetics.alleles.AlleleTolerance; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.Vec3i; public class BeeGenome extends Genome implements IBeeGenome { /** @@ -90,7 +88,7 @@ public class BeeGenome extends Genome implements IBeeGenome { return null; } - IAlleleSpecies species = getSpeciesDirectly(itemStack); + IAlleleSpecies species = getSpeciesDirectly(BeeManager.beeRoot, itemStack); if (species instanceof IAlleleBeeSpecies) { return (IAlleleBeeSpecies) species; } diff --git a/src/main/java/forestry/apiculture/genetics/BeeRoot.java b/src/main/java/forestry/apiculture/genetics/BeeRoot.java index 87315b2f6..e4fea88a0 100644 --- a/src/main/java/forestry/apiculture/genetics/BeeRoot.java +++ b/src/main/java/forestry/apiculture/genetics/BeeRoot.java @@ -17,15 +17,7 @@ import java.util.Collections; import java.util.Locale; import java.util.Map.Entry; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - -import net.minecraftforge.fml.common.FMLCommonHandler; - import forestry.api.apiculture.BeeManager; import forestry.api.apiculture.EnumBeeChromosome; import forestry.api.apiculture.EnumBeeType; @@ -53,6 +45,11 @@ import forestry.apiculture.BeeHousingModifier; import forestry.apiculture.BeekeepingLogic; import forestry.apiculture.PluginApiculture; import forestry.core.genetics.SpeciesRoot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.FMLCommonHandler; public class BeeRoot extends SpeciesRoot implements IBeeRoot { @@ -371,7 +368,7 @@ public class BeeRoot extends SpeciesRoot implements IBeeRoot { } @Override - public IChromosomeType getKaryotypeKey() { + public IChromosomeType getSpeciesChromosomeType() { return EnumBeeChromosome.SPECIES; } diff --git a/src/main/java/forestry/arboriculture/PluginArboriculture.java b/src/main/java/forestry/arboriculture/PluginArboriculture.java index cf0857248..1e4117040 100644 --- a/src/main/java/forestry/arboriculture/PluginArboriculture.java +++ b/src/main/java/forestry/arboriculture/PluginArboriculture.java @@ -17,34 +17,12 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLeaves; -import net.minecraft.block.BlockNewLeaf; -import net.minecraft.block.BlockOldLeaf; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.IFuelHandler; -import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.fml.common.registry.VillagerRegistry; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.oredict.OreDictionary; - import forestry.api.arboriculture.EnumForestryWoodType; import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumPileType; import forestry.api.arboriculture.EnumVanillaWoodType; import forestry.api.arboriculture.IAlleleFruit; +import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.IWoodType; import forestry.api.arboriculture.TreeManager; @@ -95,6 +73,27 @@ import forestry.factory.recipes.FabricatorRecipe; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; import forestry.plugins.ForestryPluginUids; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLeaves; +import net.minecraft.block.BlockNewLeaf; +import net.minecraft.block.BlockOldLeaf; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.IFuelHandler; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.common.registry.VillagerRegistry; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.oredict.OreDictionary; @ForestryPlugin(pluginID = ForestryPluginUids.ARBORICULTURE, name = "Arboriculture", author = "Binnie & SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.arboriculture.description") public class PluginArboriculture extends BlankForestryPlugin { @@ -395,10 +394,11 @@ public class PluginArboriculture extends BlankForestryPlugin { 'Y', "chestWood"); //Wood Piles - for(ITree tree : TreeManager.treeRoot.getIndividualTemplates()){ - ItemStack log = tree.getGenome().getPrimary().getWoodProvider().getWoodStack().copy(); + for (ITree tree : TreeManager.treeRoot.getIndividualTemplates()) { + IAlleleTreeSpecies treeSpecies = tree.getGenome().getPrimary(); + ItemStack log = treeSpecies.getWoodProvider().getWoodStack().copy(); log.stackSize = 1; - ItemStack woodPile = BlockPile.createWoodPile(tree); + ItemStack woodPile = BlockPile.createWoodPile(treeSpecies); RecipeUtil.addShapelessRecipe(woodPile, log, log, log, log); } diff --git a/src/main/java/forestry/arboriculture/VillagerArboristTrades.java b/src/main/java/forestry/arboriculture/VillagerArboristTrades.java index 5e24d9573..81a8be149 100644 --- a/src/main/java/forestry/arboriculture/VillagerArboristTrades.java +++ b/src/main/java/forestry/arboriculture/VillagerArboristTrades.java @@ -7,12 +7,6 @@ import java.util.Collection; import java.util.List; import java.util.Random; -import net.minecraft.entity.passive.EntityVillager; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; -import net.minecraft.village.MerchantRecipe; -import net.minecraft.village.MerchantRecipeList; - import forestry.api.arboriculture.EnumForestryWoodType; import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.TreeManager; @@ -22,6 +16,11 @@ import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IIndividual; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.village.MerchantRecipe; +import net.minecraft.village.MerchantRecipeList; public class VillagerArboristTrades { @@ -120,7 +119,7 @@ public class VillagerArboristTrades { j = this.emeraldPriceInfo.getPrice(random); } - IChromosomeType treeSpeciesType = TreeManager.treeRoot.getKaryotypeKey(); + IChromosomeType treeSpeciesType = TreeManager.treeRoot.getSpeciesChromosomeType(); Collection registeredSpecies = AlleleManager.alleleRegistry.getRegisteredAlleles(treeSpeciesType); List potentialSpecies = new ArrayList<>(); for (IAllele allele : registeredSpecies) { diff --git a/src/main/java/forestry/arboriculture/blocks/BlockPile.java b/src/main/java/forestry/arboriculture/blocks/BlockPile.java index 138da742b..ca9520378 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockPile.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockPile.java @@ -1,7 +1,5 @@ package forestry.arboriculture.blocks; -import com.google.common.collect.Lists; - import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.EnumMap; @@ -9,6 +7,36 @@ import java.util.List; import java.util.Map; import java.util.Random; +import com.google.common.collect.Lists; +import forestry.api.arboriculture.EnumPileType; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.IWoodProvider; +import forestry.api.arboriculture.TreeManager; +import forestry.api.core.IModelManager; +import forestry.api.core.ISpriteRegister; +import forestry.api.core.IStateMapperRegister; +import forestry.api.core.ITextureManager; +import forestry.api.core.Tabs; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.api.multiblock.ICharcoalPileComponent; +import forestry.apiculture.blocks.BlockCandle; +import forestry.arboriculture.PluginArboriculture; +import forestry.arboriculture.genetics.Tree; +import forestry.arboriculture.multiblock.EnumPilePosition; +import forestry.arboriculture.multiblock.ICharcoalPileControllerInternal; +import forestry.arboriculture.render.PileParticleCallback; +import forestry.arboriculture.render.PileStateMapper; +import forestry.arboriculture.tiles.TilePile; +import forestry.core.PluginCore; +import forestry.core.blocks.BlockStructure; +import forestry.core.blocks.propertys.UnlistedBlockAccess; +import forestry.core.blocks.propertys.UnlistedBlockPos; +import forestry.core.multiblock.MultiblockLogic; +import forestry.core.proxy.Proxies; +import forestry.core.render.ParticleHelper; +import forestry.core.tiles.TileUtil; import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; @@ -40,42 +68,12 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; - import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import forestry.api.arboriculture.EnumPileType; -import forestry.api.arboriculture.IAlleleTreeSpecies; -import forestry.api.arboriculture.ITree; -import forestry.api.arboriculture.TreeManager; -import forestry.api.core.IModelManager; -import forestry.api.core.ISpriteRegister; -import forestry.api.core.IStateMapperRegister; -import forestry.api.core.ITextureManager; -import forestry.api.core.Tabs; -import forestry.api.genetics.AlleleManager; -import forestry.api.genetics.IAllele; -import forestry.api.multiblock.ICharcoalPileComponent; -import forestry.apiculture.blocks.BlockCandle; -import forestry.arboriculture.PluginArboriculture; -import forestry.arboriculture.genetics.Tree; -import forestry.arboriculture.multiblock.EnumPilePosition; -import forestry.arboriculture.multiblock.ICharcoalPileControllerInternal; -import forestry.arboriculture.render.PileParticleCallback; -import forestry.arboriculture.render.PileStateMapper; -import forestry.arboriculture.tiles.TilePile; -import forestry.core.PluginCore; -import forestry.core.blocks.BlockStructure; -import forestry.core.blocks.propertys.UnlistedBlockAccess; -import forestry.core.blocks.propertys.UnlistedBlockPos; -import forestry.core.multiblock.MultiblockLogic; -import forestry.core.proxy.Proxies; -import forestry.core.render.ParticleHelper; -import forestry.core.tiles.TileUtil; - public abstract class BlockPile extends BlockStructure implements ITileEntityProvider, IStateMapperRegister, ISpriteRegister { /** @@ -318,13 +316,15 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro @SideOnly(Side.CLIENT) @Override public void getSubBlocks(Item item, CreativeTabs tab, List subItems) { - if(getPileType() == EnumPileType.WOOD){ + if (getPileType() == EnumPileType.WOOD) { List woodPiles = new ArrayList<>(); - for(ITree tree : TreeManager.treeRoot.getIndividualTemplates()) { - woodPiles.add(createWoodPile(tree)); + for (ITree tree : TreeManager.treeRoot.getIndividualTemplates()) { + IAlleleTreeSpecies treeSpecies = tree.getGenome().getPrimary(); + ItemStack woodPile = createWoodPile(treeSpecies); + woodPiles.add(woodPile); } subItems.addAll(woodPiles); - }else if(getPileType() == EnumPileType.DIRT){ + } else if (getPileType() == EnumPileType.DIRT) { super.getSubBlocks(item, tab, subItems); } } @@ -412,8 +412,9 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro ICharcoalPileComponent pile = (ICharcoalPileComponent) tile; if (getPileType() == EnumPileType.ASH) { - if (pile.getTree() != null) { - ItemStack charcoal = new ItemStack(PluginArboriculture.items.charcoal, pile.getTree().getGenome().getCarbonization(), pile.getTree().getGenome().getCombustibility()); + if (pile.getTreeSpecies() != null) { + IWoodProvider woodProvider = pile.getTreeSpecies().getWoodProvider(); + ItemStack charcoal = new ItemStack(PluginArboriculture.items.charcoal, woodProvider.getCarbonization(), woodProvider.getCombustibility()); list.add(charcoal); list.add(new ItemStack(PluginCore.items.ash, 3)); } else { @@ -423,7 +424,7 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro } else if (getPileType() == EnumPileType.DIRT) { list.add(new ItemStack(this)); } else { - list.add(createWoodPile(pile.getTree())); + list.add(createWoodPile(pile.getTreeSpecies())); } } return list; @@ -485,7 +486,7 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro if(getPileType() == EnumPileType.WOOD){ TileEntity tile = world.getTileEntity(pos); if (tile instanceof ICharcoalPileComponent) { - return createWoodPile(((ICharcoalPileComponent) tile).getTree()); + return createWoodPile(((ICharcoalPileComponent) tile).getTreeSpecies()); } }else if(getPileType() == EnumPileType.DIRT){ return super.getPickBlock(state, target, world, pos, player); @@ -528,10 +529,19 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro IBlockState blockState = world.getBlockState(pos); return ParticleHelper.addDestroyEffects(world, this, blockState, pos, effectRenderer, particleCallback); } - - public static ITree getTree(ItemStack stack){ + + public static IAlleleTreeSpecies getTreeSpecies(ItemStack stack) { if (stack != null) { - return new Tree(stack.getTagCompound().getCompoundTag("ContainedTree")); + NBTTagCompound tagCompound = stack.getTagCompound(); + + // legacy + if (tagCompound.hasKey("ContainedTree")) { + ITree tree = new Tree(tagCompound.getCompoundTag("ContainedTree")); + return tree.getGenome().getPrimary(); + } + + String treeSpeciesUid = tagCompound.getString("TreeSpecies"); + return (IAlleleTreeSpecies) AlleleManager.alleleRegistry.getAllele(treeSpeciesUid); } return null; } @@ -541,10 +551,9 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro if(getPileType() == EnumPileType.WOOD){ TileEntity tile = world.getTileEntity(pos); if (tile instanceof ICharcoalPileComponent) { - - ITree tree = ((ICharcoalPileComponent)tile).getTree(); - if(tree != null){ - ItemStack wood = tree.getGenome().getPrimary().getWoodProvider().getWoodStack(); + IAlleleTreeSpecies tree = ((ICharcoalPileComponent) tile).getTreeSpecies(); + if (tree != null) { + ItemStack wood = tree.getWoodProvider().getWoodStack(); if(wood != null){ Block block = Block.getBlockFromItem(wood.getItem()); return block.getFlammability(world, pos, face); @@ -560,10 +569,9 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro if(getPileType() == EnumPileType.WOOD){ TileEntity tile = world.getTileEntity(pos); if (tile instanceof ICharcoalPileComponent) { - - ITree tree = ((ICharcoalPileComponent)tile).getTree(); + IAlleleTreeSpecies tree = ((ICharcoalPileComponent) tile).getTreeSpecies(); if(tree != null){ - ItemStack wood = tree.getGenome().getPrimary().getWoodProvider().getWoodStack(); + ItemStack wood = tree.getWoodProvider().getWoodStack(); if(wood != null){ Block block = Block.getBlockFromItem(wood.getItem()); return block.getFireSpreadSpeed(world, pos, face); @@ -580,11 +588,11 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro if(getPileType() == EnumPileType.WOOD){ TileEntity tile = world.getTileEntity(pos); if (tile instanceof ICharcoalPileComponent) { - - ITree tree = ((ICharcoalPileComponent)tile).getTree(); + + IAlleleTreeSpecies tree = ((ICharcoalPileComponent) tile).getTreeSpecies(); if(tree != null){ - ItemStack wood = tree.getGenome().getPrimary().getWoodProvider().getWoodStack(); - if(wood != null){ + ItemStack wood = tree.getWoodProvider().getWoodStack(); + if (wood != null) { Block block = Block.getBlockFromItem(wood.getItem()); return block.getStateFromMeta(wood.getMetadata()).getBlockHardness(world, pos); } @@ -593,14 +601,12 @@ public abstract class BlockPile extends BlockStructure implements ITileEntityPro } return super.getBlockHardness(blockState, world, pos); } - - public static ItemStack createWoodPile(ITree tree) { - if (tree != null) { + + public static ItemStack createWoodPile(IAlleleTreeSpecies treeSpecies) { + if (treeSpecies != null) { ItemStack stack = new ItemStack(PluginArboriculture.blocks.piles.get(EnumPileType.WOOD)); - NBTTagCompound nbtTag = new NBTTagCompound(); - tree.writeToNBT(nbtTag); NBTTagCompound nbtItem = new NBTTagCompound(); - nbtItem.setTag("ContainedTree", nbtTag); + nbtItem.setString("TreeSpecies", treeSpecies.getUID()); stack.setTagCompound(nbtItem); return stack; } diff --git a/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java b/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java index 537c72237..04e5f951e 100755 --- a/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java +++ b/src/main/java/forestry/arboriculture/genetics/GrowthProvider.java @@ -11,47 +11,23 @@ package forestry.arboriculture.genetics; import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; -import net.minecraft.block.state.IBlockState; +import forestry.api.arboriculture.IGrowthProvider; +import forestry.api.arboriculture.ITreeGenome; +import forestry.core.utils.Translator; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; -import forestry.api.arboriculture.EnumGrowthConditions; -import forestry.api.arboriculture.IGrowthProvider; -import forestry.api.arboriculture.ITree; -import forestry.api.arboriculture.ITreeGenome; -import forestry.api.core.ForestryAPI; -import forestry.arboriculture.tiles.TileSapling; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.Translator; - +/** + * @deprecated this is being removed to simplify trees + */ +@Deprecated public class GrowthProvider implements IGrowthProvider { @Override @Nullable public BlockPos canGrow(ITreeGenome genome, World world, BlockPos pos, int expectedGirth, int expectedHeight) { - BlockPos growthPos = hasSufficientSaplingsAroundSapling(genome, world, pos, expectedGirth); - if (growthPos == null) { - return null; - } - - if (!hasRoom(world, growthPos, expectedGirth, expectedHeight)) { - return null; - } - - if (getGrowthConditions(genome, world, growthPos) == EnumGrowthConditions.HOSTILE) { - return null; - } - - return growthPos; - } - - @Override - public EnumGrowthConditions getGrowthConditions(ITreeGenome genome, World world, BlockPos pos) { - return getConditionFromLight(world, pos); + return TreeGrowthHelper.canGrow(world, genome, pos, expectedGirth, expectedHeight); } @Override @@ -63,118 +39,4 @@ public class GrowthProvider implements IGrowthProvider { public String[] getInfo() { return new String[0]; } - - protected static EnumGrowthConditions getConditionsFromRainfall(World world, BlockPos pos, float min, float max) { - float humidity = ForestryAPI.climateManager.getHumidity(world, pos); - - if (humidity < min || humidity > max) { - return EnumGrowthConditions.HOSTILE; - } - - return EnumGrowthConditions.EXCELLENT; - } - - protected static EnumGrowthConditions getConditionsFromTemperature(World world, BlockPos pos, float min, float max) { - float biomeTemperature = ForestryAPI.climateManager.getTemperature(world, pos); - if (biomeTemperature < min || biomeTemperature > max) { - return EnumGrowthConditions.HOSTILE; - } - - return EnumGrowthConditions.EXCELLENT; - } - - protected static EnumGrowthConditions getConditionFromLight(World world, BlockPos pos) { - int lightValue = world.getLightFromNeighbors(pos.up()); - - if (lightValue > 13) { - return EnumGrowthConditions.EXCELLENT; - } else if (lightValue > 11) { - return EnumGrowthConditions.GOOD; - } else if (lightValue > 8) { - return EnumGrowthConditions.NORMAL; - } else if (lightValue > 6) { - return EnumGrowthConditions.PALTRY; - } else { - return EnumGrowthConditions.HOSTILE; - } - } - - private static boolean hasRoom(World world, BlockPos pos, int expectedGirth, int expectedHeight) { - Vec3i area = new Vec3i(expectedGirth, expectedHeight + 1, expectedGirth); - return checkArea(world, pos.up(), area); - } - - private static boolean checkArea(World world, BlockPos start, Vec3i area) { - for (int x = 0; x < area.getX(); x++) { - for (int y = 0; y < area.getY(); y++) { - for (int z = 0; z < area.getZ(); z++) { - BlockPos pos = start.add(x, y, z); - IBlockState blockState = world.getBlockState(pos); - if (!blockState.getBlock().isReplaceable(world, pos)) { - return false; - } - } - } - } - return true; - } - - /** - * Checks an area for saplings. - * If saplings need to be 2x2, 3x3, etc, it will check all configurations in which pos is included in that area. - * Uses a knownSaplings cache to avoid checking the same saplings multiple times. - */ - @Nullable - private static BlockPos hasSufficientSaplingsAroundSapling(ITreeGenome genome, World world, BlockPos saplingPos, int expectedGirth) { - final int checkSize = (expectedGirth * 2) - 1; - final int offset = expectedGirth - 1; - final Map knownSaplings = new HashMap<>(checkSize * checkSize); - - for (int x = -offset; x <= 0; x++) { - for (int z = -offset; z <= 0; z++) { - BlockPos startPos = saplingPos.add(x, 0, z); - if (checkForSaplings(genome, world, startPos, expectedGirth, knownSaplings)) { - return startPos; - } - } - } - - return null; - } - - private static boolean checkForSaplings(ITreeGenome genome, World world, BlockPos startPos, int girth, Map knownSaplings) { - for (int x = 0; x < girth; x++) { - for (int z = 0; z < girth; z++) { - BlockPos checkPos = startPos.add(x, 0, z); - Boolean knownSapling = knownSaplings.get(checkPos); - if (knownSapling == null) { - knownSapling = isSapling(genome, world, checkPos); - knownSaplings.put(checkPos, knownSapling); - } - - if (!knownSapling) { - return false; - } - } - } - return true; - } - - private static boolean isSapling(ITreeGenome genome, World world, BlockPos pos) { - if (!world.isBlockLoaded(pos)) { - return false; - } - - if (world.isAirBlock(pos)) { - return false; - } - - TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class); - if (sapling == null) { - return false; - } - - ITree tree = sapling.getTree(); - return tree != null && tree.getGenome().getPrimary().getUID().equals(genome.getPrimary().getUID()); - } } diff --git a/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java b/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java deleted file mode 100755 index f10e58808..000000000 --- a/src/main/java/forestry/arboriculture/genetics/GrowthProviderTropical.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture.genetics; - -import java.util.EnumSet; - -import net.minecraft.init.Biomes; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import forestry.api.arboriculture.EnumGrowthConditions; -import forestry.api.arboriculture.ITreeGenome; -import forestry.core.utils.Translator; - -public class GrowthProviderTropical extends GrowthProvider { - - @Override - public EnumGrowthConditions getGrowthConditions(ITreeGenome genome, World world, BlockPos pos) { - EnumGrowthConditions light = getConditionFromLight(world, pos); - EnumGrowthConditions moisture = getConditionsFromRainfall(world, pos, Biomes.JUNGLE.getRainfall(), 2.0f); - - float jungleTemperature = Biomes.JUNGLE.getFloatTemperature(pos); - float desertTemperature = Biomes.DESERT.getFloatTemperature(pos); - EnumGrowthConditions temperature = getConditionsFromTemperature(world, pos, jungleTemperature, desertTemperature - 0.1f); - - EnumSet conditions = EnumSet.of(light, moisture, temperature); - - EnumGrowthConditions result = EnumGrowthConditions.HOSTILE; - for (EnumGrowthConditions cond : conditions) { - if (cond == EnumGrowthConditions.HOSTILE) { - return EnumGrowthConditions.HOSTILE; - } - - if (cond.ordinal() > result.ordinal()) { - result = cond; - } - } - - return result; - } - - @Override - public String getDescription() { - return Translator.translateToLocal("for.growth.tropical"); - } - -} diff --git a/src/main/java/forestry/arboriculture/genetics/Tree.java b/src/main/java/forestry/arboriculture/genetics/Tree.java index 1bae06222..b662bccb1 100755 --- a/src/main/java/forestry/arboriculture/genetics/Tree.java +++ b/src/main/java/forestry/arboriculture/genetics/Tree.java @@ -14,34 +14,16 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; -import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.WorldGenerator; - import com.mojang.authlib.GameProfile; - -import net.minecraftforge.common.EnumPlantType; -import net.minecraftforge.common.IPlantable; - -import forestry.api.arboriculture.EnumGrowthConditions; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleLeafEffect; import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.IArboristTracker; import forestry.api.arboriculture.IFruitProvider; -import forestry.api.arboriculture.IGrowthProvider; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.ITreeGenome; import forestry.api.arboriculture.ITreeMutation; @@ -57,6 +39,18 @@ import forestry.core.config.Config; import forestry.core.genetics.Chromosome; import forestry.core.genetics.Individual; import forestry.core.utils.Translator; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; +import net.minecraftforge.common.EnumPlantType; +import net.minecraftforge.common.IPlantable; public class Tree extends Individual implements ITree, IPlantable { @@ -65,13 +59,8 @@ public class Tree extends Individual implements ITree, IPlantable { @Nullable private ITreeGenome mate; - private final EnumSet plantTypes; - private EnumPlantType plantType; - public Tree(@Nonnull ITreeGenome genome) { this.genome = genome; - plantTypes = genome.getPlantTypes(); - plantTypes.add(genome.getPrimary().getPlantType()); } public Tree(@Nonnull NBTTagCompound nbttagcompound) { @@ -83,9 +72,6 @@ public class Tree extends Individual implements ITree, IPlantable { this.genome = TreeDefinition.Oak.getGenome(); } - this.plantTypes = genome.getPlantTypes(); - this.plantTypes.add(genome.getPrimary().getPlantType()); - if (nbttagcompound.hasKey("Mate")) { mate = new TreeGenome(nbttagcompound.getCompoundTag("Mate")); } @@ -164,12 +150,8 @@ public class Tree extends Individual implements ITree, IPlantable { } Block block = blockState.getBlock(); - - for (EnumPlantType type : getPlantTypes()) { - this.plantType = type; - if (block.canSustainPlant(blockState, world, blockPos, EnumFacing.UP, this)) { - return true; - } + if (block.canSustainPlant(blockState, world, blockPos, EnumFacing.UP, this)) { + return true; } return false; @@ -177,7 +159,7 @@ public class Tree extends Individual implements ITree, IPlantable { @Override public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) { - return plantType; + return genome.getPrimary().getPlantType(); } @Override @@ -188,8 +170,7 @@ public class Tree extends Individual implements ITree, IPlantable { @Override @Nullable public BlockPos canGrow(World world, BlockPos pos, int expectedGirth, int expectedHeight) { - IGrowthProvider growthProvider = genome.getGrowthProvider(); - return growthProvider.canGrow(genome, world, pos, expectedGirth, expectedHeight); + return TreeGrowthHelper.canGrow(world, genome, pos, expectedGirth, expectedHeight); } @Override @@ -197,11 +178,6 @@ public class Tree extends Individual implements ITree, IPlantable { return genome.getMaturationTime(); } - @Override - public EnumGrowthConditions getGrowthCondition(World world, BlockPos pos) { - return genome.getGrowthProvider().getGrowthConditions(getGenome(), world, pos); - } - @Override public int getGirth() { return genome.getGirth(); @@ -275,11 +251,6 @@ public class Tree extends Individual implements ITree, IPlantable { return genome.getActiveAllele(chromosome).getUID().equals(genome.getInactiveAllele(chromosome).getUID()); } - @Override - public EnumSet getPlantTypes() { - return plantTypes; - } - @Override public void addTooltip(List list) { @@ -302,8 +273,8 @@ public class Tree extends Individual implements ITree, IPlantable { String girth = TextFormatting.AQUA + "G: " + String.format("%sx%s", genome.getGirth(), genome.getGirth()); String saplings = TextFormatting.YELLOW + "S: " + genome.getActiveAllele(EnumTreeChromosome.FERTILITY).getName(); String yield = TextFormatting.WHITE + "Y: " + genome.getActiveAllele(EnumTreeChromosome.YIELD).getName(); - String combustibility = TextFormatting.DARK_GRAY + "CO: " + genome.getCombustibility(); - String carbonization = TextFormatting.GRAY + "CA: " + genome.getCarbonization(); + String combustibility = TextFormatting.DARK_GRAY + "CO: " + primary.getWoodProvider().getCombustibility(); + String carbonization = TextFormatting.GRAY + "CA: " + secondary.getWoodProvider().getCarbonization(); list.add(String.format("%s, %s", saplings, maturation)); list.add(String.format("%s, %s", height, girth)); list.add(String.format("%s, %s", yield, sappiness)); diff --git a/src/main/java/forestry/arboriculture/genetics/TreeAlyzerPlugin.java b/src/main/java/forestry/arboriculture/genetics/TreeAlyzerPlugin.java index 5bfc30066..0224e4b4d 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeAlyzerPlugin.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeAlyzerPlugin.java @@ -11,23 +11,14 @@ package forestry.arboriculture.genetics; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.TextFormatting; - -import net.minecraftforge.common.EnumPlantType; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; -import forestry.api.arboriculture.IAlleleGrowth; import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.TreeManager; @@ -38,13 +29,16 @@ import forestry.api.genetics.IFruitFamily; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.genetics.alleles.AlleleFruit; import forestry.core.config.Config; -import forestry.core.genetics.alleles.AllelePlantType; import forestry.core.gui.GuiAlyzer; import forestry.core.gui.TextLayoutHelper; import forestry.core.gui.widgets.ItemStackWidget; import forestry.core.gui.widgets.WidgetManager; import forestry.core.proxy.Proxies; import forestry.core.utils.Translator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class TreeAlyzerPlugin implements IAlyzerPlugin { public static final TreeAlyzerPlugin INSTANCE = new TreeAlyzerPlugin(); @@ -110,12 +104,6 @@ public class TreeAlyzerPlugin implements IAlyzerPlugin { textLayout.newLineCompressed(); gui.drawChromosomeRow(Translator.translateToLocal("for.gui.effect"), tree, EnumTreeChromosome.EFFECT); - textLayout.newLineCompressed(); - IAlleleInteger activeCombustibility = (IAlleleInteger) tree.getGenome().getActiveAllele(EnumTreeChromosome.COMBUSTIBILITY); - IAlleleInteger inactiveCombustibility = (IAlleleInteger) tree.getGenome().getInactiveAllele(EnumTreeChromosome.COMBUSTIBILITY); - textLayout.drawLine(Translator.translateToLocal("for.gui.combustibility"), GuiAlyzer.COLUMN_0); - gui.drawLine(Integer.toString(activeCombustibility.getValue()), GuiAlyzer.COLUMN_1, tree, EnumTreeChromosome.COMBUSTIBILITY, false); - gui.drawLine(Integer.toString(inactiveCombustibility.getValue()), GuiAlyzer.COLUMN_2, tree, EnumTreeChromosome.COMBUSTIBILITY, true); textLayout.endPage(); } @@ -140,20 +128,24 @@ public class TreeAlyzerPlugin implements IAlyzerPlugin { textLayout.newLine(); textLayout.newLine(); - - IAlleleInteger activeCarbonization = (IAlleleInteger) tree.getGenome().getActiveAllele(EnumTreeChromosome.CARBONIZATION); - IAlleleInteger inactiveCarbonization = (IAlleleInteger) tree.getGenome().getInactiveAllele(EnumTreeChromosome.CARBONIZATION); + + IAlleleTreeSpecies activeSpecies = (IAlleleTreeSpecies) tree.getGenome().getActiveAllele(EnumTreeChromosome.SPECIES); + IAlleleTreeSpecies inActiveSpecies = (IAlleleTreeSpecies) tree.getGenome().getInactiveAllele(EnumTreeChromosome.SPECIES); + + int activeCombustibility = activeSpecies.getWoodProvider().getCombustibility(); + int inactiveCombustibility = inActiveSpecies.getWoodProvider().getCombustibility(); + textLayout.drawLine(Translator.translateToLocal("for.gui.combustibility"), GuiAlyzer.COLUMN_0); + gui.drawLine(Integer.toString(activeCombustibility), GuiAlyzer.COLUMN_1, tree, EnumTreeChromosome.SPECIES, false); + gui.drawLine(Integer.toString(inactiveCombustibility), GuiAlyzer.COLUMN_2, tree, EnumTreeChromosome.SPECIES, true); + + textLayout.newLineCompressed(); + + int activeCarbonization = activeSpecies.getWoodProvider().getCarbonization(); + int inactiveCarbonization = inActiveSpecies.getWoodProvider().getCarbonization(); textLayout.drawLine(Translator.translateToLocal("for.gui.carbonization"), GuiAlyzer.COLUMN_0); - gui.drawLine(Integer.toString(activeCarbonization.getValue()), GuiAlyzer.COLUMN_1, tree, EnumTreeChromosome.CARBONIZATION, false); - gui.drawLine(Integer.toString(inactiveCarbonization.getValue()), GuiAlyzer.COLUMN_2, tree, EnumTreeChromosome.CARBONIZATION, true); - textLayout.newLineCompressed(); - - textLayout.drawLine(Translator.translateToLocal("for.gui.growth"), GuiAlyzer.COLUMN_0); - gui.drawLine(tree.getGenome().getGrowthProvider().getDescription(), GuiAlyzer.COLUMN_1, tree, EnumTreeChromosome.GROWTH, false); - gui.drawLine(((IAlleleGrowth) tree.getGenome().getInactiveAllele(EnumTreeChromosome.GROWTH)).getProvider().getDescription(), GuiAlyzer.COLUMN_2, tree, - EnumTreeChromosome.GROWTH, true); - - textLayout.newLineCompressed(); + gui.drawLine(Integer.toString(activeCarbonization), GuiAlyzer.COLUMN_1, tree, EnumTreeChromosome.SPECIES, false); + gui.drawLine(Integer.toString(inactiveCarbonization), GuiAlyzer.COLUMN_2, tree, EnumTreeChromosome.SPECIES, true); + textLayout.newLine(); textLayout.drawLine(Translator.translateToLocal("for.gui.native"), GuiAlyzer.COLUMN_0); textLayout.drawLine(Translator.translateToLocal("for.gui." + tree.getGenome().getPrimary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), GuiAlyzer.COLUMN_1, @@ -161,38 +153,14 @@ public class TreeAlyzerPlugin implements IAlyzerPlugin { textLayout.drawLine(Translator.translateToLocal("for.gui." + tree.getGenome().getSecondary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), GuiAlyzer.COLUMN_2, speciesDominance1); - textLayout.newLineCompressed(); - - textLayout.drawLine(Translator.translateToLocal("for.gui.tolerated"), GuiAlyzer.COLUMN_0); - - List activeTolerated = new ArrayList<>(tree.getGenome().getPlantTypes()); - List inactiveTolerated = Collections.emptyList(); - - IAllele inactiveAllelePlant = tree.getGenome().getInactiveAllele(EnumTreeChromosome.PLANT); - if (inactiveAllelePlant instanceof AllelePlantType) { - inactiveTolerated = new ArrayList<>(((AllelePlantType) inactiveAllelePlant).getPlantTypes()); - } - - int max = Math.max(activeTolerated.size(), inactiveTolerated.size()); - for (int i = 0; i < max; i++) { - if (i > 0) { - textLayout.newLineCompressed(); - } - if (activeTolerated.size() > i) { - gui.drawLine(Translator.translateToLocal("for.gui." + activeTolerated.get(i).toString().toLowerCase(Locale.ENGLISH)), GuiAlyzer.COLUMN_1, tree, EnumTreeChromosome.PLANT, false); - } - if (inactiveTolerated.size() > i) { - gui.drawLine(Translator.translateToLocal("for.gui." + inactiveTolerated.get(i).toString().toLowerCase(Locale.ENGLISH)), GuiAlyzer.COLUMN_2, tree, EnumTreeChromosome.PLANT, true); - } - } - textLayout.newLineCompressed(); + textLayout.newLine(); // FRUITS textLayout.drawLine(Translator.translateToLocal("for.gui.supports"), GuiAlyzer.COLUMN_0); List families0 = new ArrayList<>(tree.getGenome().getPrimary().getSuitableFruit()); List families1 = new ArrayList<>(tree.getGenome().getSecondary().getSuitableFruit()); - max = Math.max(families0.size(), families1.size()); + int max = Math.max(families0.size(), families1.size()); for (int i = 0; i < max; i++) { if (i > 0) { textLayout.newLineCompressed(); @@ -206,8 +174,7 @@ public class TreeAlyzerPlugin implements IAlyzerPlugin { } } - - textLayout.newLine(); + textLayout.newLine(); int fruitDominance0 = gui.getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).isDominant()); diff --git a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java index bfafe7c64..fffa44725 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeDefinition.java @@ -10,22 +10,11 @@ ******************************************************************************/ package forestry.arboriculture.genetics; -import java.awt.Color; +import java.awt.*; import java.util.Arrays; import java.util.Locale; -import net.minecraft.block.Block; -import net.minecraft.block.BlockLog; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.IStringSerializable; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.gen.feature.WorldGenerator; - import com.mojang.authlib.GameProfile; - import forestry.api.arboriculture.EnumForestryWoodType; import forestry.api.arboriculture.EnumFruitFamily; import forestry.api.arboriculture.EnumGermlingType; @@ -50,7 +39,6 @@ import forestry.api.genetics.IAllele; import forestry.api.world.ITreeGenData; import forestry.arboriculture.PluginArboriculture; import forestry.arboriculture.genetics.alleles.AlleleFruit; -import forestry.arboriculture.genetics.alleles.AlleleGrowth; import forestry.arboriculture.models.ModelProviderFactory; import forestry.arboriculture.tiles.TileLeaves; import forestry.arboriculture.worldgen.WorldGenAcacia; @@ -94,6 +82,15 @@ import forestry.core.genetics.alleles.AlleleHelper; import forestry.core.genetics.alleles.AllelePlantType; import forestry.core.genetics.alleles.EnumAllele; import forestry.core.tiles.TileUtil; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLog; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.gen.feature.WorldGenerator; public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSerializable { Oak(TreeBranchDefinition.QUERCUS, "appleOak", "robur", false, EnumLeafType.DECIDUOUS, new Color(4764952), new Color(4764952).brighter(), EnumVanillaWoodType.OAK) { @@ -107,8 +104,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FRUITS, AlleleFruit.fruitApple); AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.AVERAGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.FASTER); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.CARBONIZATION, 5); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); } @Override @@ -132,8 +127,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.AVERAGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.FASTER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.GIRTH, 2); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.CARBONIZATION, 5); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); } @Override @@ -156,7 +149,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe protected void setAlleles(IAllele[] alleles) { AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.AVERAGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.FASTER); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 19); } @Override @@ -180,7 +172,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.LOW); AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOWER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.YIELD, EnumAllele.Yield.LOWER); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 19); //Allele.helper.set(alleles, EnumTreeChromosome.EFFECT, Allele.leavesBrimstone); } @@ -217,7 +208,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOWER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.AVERAGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.GIRTH, 2); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 21); } @Override @@ -245,7 +235,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOWER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.LARGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.GIRTH, 2); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 21); } @Override @@ -348,7 +337,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.LOW); AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOWER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.AVERAGE); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); } @Override @@ -372,7 +360,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.AVERAGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.AVERAGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.FASTER); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 19); } @Override @@ -396,7 +383,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FERTILITY, EnumAllele.Saplings.LOW); AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOWER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.AVERAGE); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); } @Override @@ -470,8 +456,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOWEST); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.SLOWEST); AlleleHelper.instance.set(alleles, EnumTreeChromosome.GIRTH, 4); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.CARBONIZATION, 3); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 18); AlleleHelper.instance.set(alleles, EnumTreeChromosome.FIREPROOF, EnumAllele.Fireproof.TRUE); } @@ -496,7 +480,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.FRUITS, AlleleFruit.fruitCocoa); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.LARGER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.FAST); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.CARBONIZATION, 5); } @Override @@ -590,7 +573,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOW); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.SLOWER); AlleleHelper.instance.set(alleles, EnumTreeChromosome.GIRTH, 3); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); } @Override @@ -658,7 +640,7 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe @Override protected void setAlleles(IAllele[] alleles) { - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); + } @Override @@ -681,7 +663,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe @Override protected void setAlleles(IAllele[] alleles) { AlleleHelper.instance.set(alleles, EnumTreeChromosome.PLANT, AllelePlantType.plantTypeDesert); - AlleleHelper.instance.set(alleles, EnumTreeChromosome.COMBUSTIBILITY, 20); } @Override @@ -876,7 +857,6 @@ public enum TreeDefinition implements ITreeDefinition, ITreeGenerator, IStringSe @Override protected void setAlleles(IAllele[] alleles) { - AlleleHelper.instance.set(alleles, EnumTreeChromosome.GROWTH, AlleleGrowth.growthTropical); AlleleHelper.instance.set(alleles, EnumTreeChromosome.HEIGHT, EnumAllele.Height.LARGE); AlleleHelper.instance.set(alleles, EnumTreeChromosome.SAPPINESS, EnumAllele.Sappiness.LOW); AlleleHelper.instance.set(alleles, EnumTreeChromosome.MATURATION, EnumAllele.Maturation.SLOW); diff --git a/src/main/java/forestry/arboriculture/genetics/TreeGenome.java b/src/main/java/forestry/arboriculture/genetics/TreeGenome.java index 8139d68da..a1b2fc257 100755 --- a/src/main/java/forestry/arboriculture/genetics/TreeGenome.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeGenome.java @@ -11,20 +11,12 @@ package forestry.arboriculture.genetics; import javax.annotation.Nonnull; -import java.util.EnumSet; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import net.minecraftforge.common.EnumPlantType; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; -import forestry.api.arboriculture.IAlleleGrowth; import forestry.api.arboriculture.IAlleleLeafEffect; import forestry.api.arboriculture.IAlleleTreeSpecies; import forestry.api.arboriculture.IFruitProvider; -import forestry.api.arboriculture.IGrowthProvider; import forestry.api.arboriculture.ITreeGenome; import forestry.api.arboriculture.TreeManager; import forestry.api.genetics.IAlleleFloat; @@ -33,7 +25,8 @@ import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.ISpeciesRoot; import forestry.core.genetics.Genome; -import forestry.core.genetics.alleles.AllelePlantType; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class TreeGenome extends Genome implements ITreeGenome { @@ -51,7 +44,7 @@ public class TreeGenome extends Genome implements ITreeGenome { return null; } - IAlleleSpecies species = getSpeciesDirectly(itemStack); + IAlleleSpecies species = getSpeciesDirectly(TreeManager.treeRoot, itemStack); if (species instanceof IAlleleTreeSpecies) { return (IAlleleTreeSpecies) species; } @@ -75,11 +68,6 @@ public class TreeGenome extends Genome implements ITreeGenome { return ((IAlleleFruit) getActiveAllele(EnumTreeChromosome.FRUITS)).getProvider(); } - @Override - public IGrowthProvider getGrowthProvider() { - return ((IAlleleGrowth) getActiveAllele(EnumTreeChromosome.GROWTH)).getProvider(); - } - @Override public float getHeight() { return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.HEIGHT)).getValue(); @@ -100,11 +88,6 @@ public class TreeGenome extends Genome implements ITreeGenome { return ((IAlleleFloat) getActiveAllele(EnumTreeChromosome.SAPPINESS)).getValue(); } - @Override - public EnumSet getPlantTypes() { - return ((AllelePlantType) getActiveAllele(EnumTreeChromosome.PLANT)).getPlantTypes(); - } - @Override public int getMaturationTime() { return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.MATURATION)).getValue(); @@ -115,16 +98,6 @@ public class TreeGenome extends Genome implements ITreeGenome { return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.GIRTH)).getValue(); } - @Override - public int getCombustibility(){ - return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.COMBUSTIBILITY)).getValue(); - } - - @Override - public int getCarbonization(){ - return ((IAlleleInteger) getActiveAllele(EnumTreeChromosome.CARBONIZATION)).getValue(); - } - @Override public IAlleleLeafEffect getEffect() { return (IAlleleLeafEffect) getActiveAllele(EnumTreeChromosome.EFFECT); diff --git a/src/main/java/forestry/arboriculture/genetics/TreeGrowthHelper.java b/src/main/java/forestry/arboriculture/genetics/TreeGrowthHelper.java new file mode 100644 index 000000000..e5d5e1f60 --- /dev/null +++ b/src/main/java/forestry/arboriculture/genetics/TreeGrowthHelper.java @@ -0,0 +1,109 @@ +package forestry.arboriculture.genetics; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; + +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.ITreeGenome; +import forestry.arboriculture.tiles.TileSapling; +import forestry.core.tiles.TileUtil; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.World; + +public class TreeGrowthHelper { + @Nullable + public static BlockPos canGrow(World world, ITreeGenome genome, BlockPos pos, int expectedGirth, int expectedHeight) { + BlockPos growthPos = hasSufficientSaplingsAroundSapling(genome, world, pos, expectedGirth); + if (growthPos == null) { + return null; + } + + if (!hasRoom(world, growthPos, expectedGirth, expectedHeight)) { + return null; + } + + return growthPos; + } + + private static boolean hasRoom(World world, BlockPos pos, int expectedGirth, int expectedHeight) { + Vec3i area = new Vec3i(expectedGirth, expectedHeight + 1, expectedGirth); + return checkArea(world, pos.up(), area); + } + + private static boolean checkArea(World world, BlockPos start, Vec3i area) { + for (int x = 0; x < area.getX(); x++) { + for (int y = 0; y < area.getY(); y++) { + for (int z = 0; z < area.getZ(); z++) { + BlockPos pos = start.add(x, y, z); + IBlockState blockState = world.getBlockState(pos); + if (!blockState.getBlock().isReplaceable(world, pos)) { + return false; + } + } + } + } + return true; + } + + /** + * Checks an area for saplings. + * If saplings need to be 2x2, 3x3, etc, it will check all configurations in which pos is included in that area. + * Uses a knownSaplings cache to avoid checking the same saplings multiple times. + */ + @Nullable + private static BlockPos hasSufficientSaplingsAroundSapling(ITreeGenome genome, World world, BlockPos saplingPos, int expectedGirth) { + final int checkSize = (expectedGirth * 2) - 1; + final int offset = expectedGirth - 1; + final Map knownSaplings = new HashMap<>(checkSize * checkSize); + + for (int x = -offset; x <= 0; x++) { + for (int z = -offset; z <= 0; z++) { + BlockPos startPos = saplingPos.add(x, 0, z); + if (checkForSaplings(genome, world, startPos, expectedGirth, knownSaplings)) { + return startPos; + } + } + } + + return null; + } + + private static boolean checkForSaplings(ITreeGenome genome, World world, BlockPos startPos, int girth, Map knownSaplings) { + for (int x = 0; x < girth; x++) { + for (int z = 0; z < girth; z++) { + BlockPos checkPos = startPos.add(x, 0, z); + Boolean knownSapling = knownSaplings.get(checkPos); + if (knownSapling == null) { + knownSapling = isSapling(genome, world, checkPos); + knownSaplings.put(checkPos, knownSapling); + } + + if (!knownSapling) { + return false; + } + } + } + return true; + } + + private static boolean isSapling(ITreeGenome genome, World world, BlockPos pos) { + if (!world.isBlockLoaded(pos)) { + return false; + } + + if (world.isAirBlock(pos)) { + return false; + } + + TileSapling sapling = TileUtil.getTile(world, pos, TileSapling.class); + if (sapling == null) { + return false; + } + + ITree tree = sapling.getTree(); + return tree != null && tree.getGenome().getPrimary().getUID().equals(genome.getPrimary().getUID()); + } +} diff --git a/src/main/java/forestry/arboriculture/genetics/TreeRoot.java b/src/main/java/forestry/arboriculture/genetics/TreeRoot.java index 3a06fe1b6..4c716fb89 100644 --- a/src/main/java/forestry/arboriculture/genetics/TreeRoot.java +++ b/src/main/java/forestry/arboriculture/genetics/TreeRoot.java @@ -18,23 +18,7 @@ import java.util.List; import java.util.Locale; import java.util.Map.Entry; -import net.minecraft.block.Block; -import net.minecraft.block.BlockHorizontal; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.oredict.OreDictionary; - import forestry.api.arboriculture.EnumGermlingType; import forestry.api.arboriculture.EnumTreeChromosome; import forestry.api.arboriculture.IAlleleFruit; @@ -65,6 +49,19 @@ import forestry.core.proxy.Proxies; import forestry.core.tiles.TileUtil; import forestry.core.utils.BlockUtil; import forestry.core.utils.GeneticsUtil; +import net.minecraft.block.Block; +import net.minecraft.block.BlockHorizontal; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.oredict.OreDictionary; public class TreeRoot extends SpeciesRoot implements ITreeRoot { @@ -423,7 +420,7 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot { } @Override - public IChromosomeType getKaryotypeKey() { + public IChromosomeType getSpeciesChromosomeType() { return EnumTreeChromosome.SPECIES; } diff --git a/src/main/java/forestry/arboriculture/genetics/WoodProvider.java b/src/main/java/forestry/arboriculture/genetics/WoodProvider.java index cf0b49239..c8b2f0056 100644 --- a/src/main/java/forestry/arboriculture/genetics/WoodProvider.java +++ b/src/main/java/forestry/arboriculture/genetics/WoodProvider.java @@ -13,12 +13,6 @@ package forestry.arboriculture.genetics; import javax.annotation.Nonnull; import java.util.Locale; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; - import forestry.api.arboriculture.EnumForestryWoodType; import forestry.api.arboriculture.IWoodProvider; import forestry.api.arboriculture.TreeManager; @@ -26,6 +20,11 @@ import forestry.api.arboriculture.WoodBlockKind; import forestry.api.core.ITextureManager; import forestry.core.config.Constants; import forestry.core.proxy.Proxies; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; public class WoodProvider implements IWoodProvider { @@ -61,4 +60,14 @@ public class WoodProvider implements IWoodProvider { return TreeManager.woodAccess.getStack(woodType, WoodBlockKind.LOG, false); } + @Override + public int getCombustibility() { + return woodType.getCombustability(); + } + + @Override + public int getCarbonization() { + return woodType.getCarbonization(); + } + } diff --git a/src/main/java/forestry/arboriculture/genetics/WoodProviderVanilla.java b/src/main/java/forestry/arboriculture/genetics/WoodProviderVanilla.java index 493f11d75..bcab0b73b 100644 --- a/src/main/java/forestry/arboriculture/genetics/WoodProviderVanilla.java +++ b/src/main/java/forestry/arboriculture/genetics/WoodProviderVanilla.java @@ -12,18 +12,17 @@ package forestry.arboriculture.genetics; import javax.annotation.Nonnull; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; - import forestry.api.arboriculture.EnumVanillaWoodType; import forestry.api.arboriculture.IWoodProvider; import forestry.api.arboriculture.TreeManager; import forestry.api.arboriculture.WoodBlockKind; import forestry.api.core.ITextureManager; import forestry.core.proxy.Proxies; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; public class WoodProviderVanilla implements IWoodProvider { @@ -80,5 +79,15 @@ public class WoodProviderVanilla implements IWoodProvider { public ItemStack getWoodStack() { return TreeManager.woodAccess.getStack(woodType, WoodBlockKind.LOG, false); } - + + @Override + public int getCombustibility() { + return woodType.getCombustability(); + } + + @Override + public int getCarbonization() { + return woodType.getCarbonization(); + } + } diff --git a/src/main/java/forestry/arboriculture/genetics/alleles/AlleleGrowth.java b/src/main/java/forestry/arboriculture/genetics/alleles/AlleleGrowth.java index e524c8645..f1d3993eb 100644 --- a/src/main/java/forestry/arboriculture/genetics/alleles/AlleleGrowth.java +++ b/src/main/java/forestry/arboriculture/genetics/alleles/AlleleGrowth.java @@ -18,10 +18,13 @@ import forestry.api.arboriculture.IAlleleGrowth; import forestry.api.arboriculture.IGrowthProvider; import forestry.api.genetics.AlleleManager; import forestry.arboriculture.genetics.GrowthProvider; -import forestry.arboriculture.genetics.GrowthProviderTropical; import forestry.core.config.Constants; import forestry.core.genetics.alleles.AlleleCategorized; +/** + * @deprecated this is being removed to simplify trees + */ +@Deprecated public class AlleleGrowth extends AlleleCategorized implements IAlleleGrowth { public static IAlleleGrowth growthLightLevel; @@ -32,7 +35,7 @@ public class AlleleGrowth extends AlleleCategorized implements IAlleleGrowth { List growthAlleles = Arrays.asList( growthLightLevel = new AlleleGrowth("lightlevel", new GrowthProvider()), growthAcacia = new AlleleGrowth("acacia", new GrowthProvider()), - growthTropical = new AlleleGrowth("tropical", new GrowthProviderTropical()) + growthTropical = new AlleleGrowth("tropical", new GrowthProvider()) ); for (IAlleleGrowth alleleGrowth : growthAlleles) { diff --git a/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java b/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java index 78c02c45f..0ee9cb5fb 100644 --- a/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java +++ b/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java @@ -10,12 +10,9 @@ ******************************************************************************/ package forestry.arboriculture.genetics.pollination; -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.arboriculture.ITree; import forestry.api.genetics.ICheckPollinatable; +import net.minecraftforge.common.EnumPlantType; public class CheckPollinatableTree implements ICheckPollinatable { @@ -26,8 +23,8 @@ public class CheckPollinatableTree implements ICheckPollinatable { } @Override - public EnumSet getPlantType() { - return tree.getPlantTypes(); + public EnumPlantType getPlantType() { + return tree.getGenome().getPrimary().getPlantType(); } @Override @@ -40,9 +37,6 @@ public class CheckPollinatableTree implements ICheckPollinatable { if (tree.getMate() != null) { return false; } - if (!(pollen instanceof ITree)) { - return false; - } return !tree.isGeneticEqual(pollen); } diff --git a/src/main/java/forestry/arboriculture/items/ItemBlockPile.java b/src/main/java/forestry/arboriculture/items/ItemBlockPile.java index 736409ed6..268a95e4f 100644 --- a/src/main/java/forestry/arboriculture/items/ItemBlockPile.java +++ b/src/main/java/forestry/arboriculture/items/ItemBlockPile.java @@ -10,6 +10,14 @@ ******************************************************************************/ package forestry.arboriculture.items; +import forestry.api.arboriculture.EnumPileType; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.arboriculture.PluginArboriculture; +import forestry.arboriculture.blocks.BlockPile; +import forestry.arboriculture.tiles.TilePile; +import forestry.core.items.ItemBlockForestry; +import forestry.core.tiles.TileUtil; +import forestry.core.utils.Translator; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -17,15 +25,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import forestry.api.arboriculture.EnumPileType; -import forestry.api.arboriculture.ITree; -import forestry.api.genetics.IAlleleSpecies; -import forestry.arboriculture.PluginArboriculture; -import forestry.arboriculture.blocks.BlockPile; -import forestry.arboriculture.tiles.TilePile; -import forestry.core.items.ItemBlockForestry; -import forestry.core.tiles.TileUtil; -import forestry.core.utils.Translator; public class ItemBlockPile extends ItemBlockForestry { @@ -52,12 +51,11 @@ public class ItemBlockPile extends ItemBlockForestry { if (!itemstack.hasTagCompound()) { return "Unknown"; } - ITree tree = BlockPile.getTree(itemstack); - if (tree == null) { + IAlleleTreeSpecies species = BlockPile.getTreeSpecies(itemstack); + if (species == null) { return "Unknown"; } - IAlleleSpecies species = tree.getGenome().getPrimary(); - + String customTreeKey = "for.trees.custom.pile." + species.getUnlocalizedName().replace("trees.species.", ""); if (Translator.canTranslateToLocal(customTreeKey)) { return Translator.translateToLocal(customTreeKey); diff --git a/src/main/java/forestry/arboriculture/models/ModelWoodPile.java b/src/main/java/forestry/arboriculture/models/ModelWoodPile.java index a5b008394..2a6364e2c 100644 --- a/src/main/java/forestry/arboriculture/models/ModelWoodPile.java +++ b/src/main/java/forestry/arboriculture/models/ModelWoodPile.java @@ -7,11 +7,9 @@ import java.util.Map; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; - import forestry.api.arboriculture.IAlleleTreeSpecies; -import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.TreeManager; -import forestry.arboriculture.genetics.Tree; +import forestry.arboriculture.blocks.BlockPile; import forestry.arboriculture.genetics.TreeDefinition; import forestry.arboriculture.tiles.TilePile; import forestry.core.blocks.propertys.UnlistedBlockAccess; @@ -62,9 +60,9 @@ public class ModelWoodPile extends BlankItemModel{ if(pile == null){ return Collections.emptyList(); } - ITree tree = pile.getTree(); - if (tree == null) { - tree = TreeManager.treeRoot.templateAsIndividual(TreeManager.treeRoot.getDefaultTemplate()); + IAlleleTreeSpecies treeSpecies = pile.getTreeSpecies(); + if (treeSpecies == null) { + treeSpecies = (IAlleleTreeSpecies) TreeManager.treeRoot.getDefaultTemplate()[TreeManager.treeRoot.getSpeciesChromosomeType().ordinal()]; } if (modelWoodPileBlock == null) { @@ -77,8 +75,8 @@ public class ModelWoodPile extends BlankItemModel{ return Collections.emptyList(); } } - - IBakedModel model = bakeModel(tree, false); + + IBakedModel model = bakeModel(treeSpecies, false); return model.getQuads(state, side, rand); } return Collections.emptyList(); @@ -103,10 +101,9 @@ public class ModelWoodPile extends BlankItemModel{ protected ItemOverrideList createOverrides() { return new PileItemOverrideList(); } - - private IBakedModel bakeModel(ITree tree, boolean isItem) { + + private IBakedModel bakeModel(IAlleleTreeSpecies treeSpecies, boolean isItem) { ImmutableMap.Builder textures = ImmutableMap.builder(); - IAlleleTreeSpecies treeSpecies = tree.getGenome().getPrimary(); String treeUID = treeSpecies.getUID(); Map map = isItem ? itemCache : blockCache; if(!map.containsKey(treeUID)){ @@ -135,14 +132,11 @@ public class ModelWoodPile extends BlankItemModel{ return null; } } - ITree tree = null; - if(stack.hasTagCompound()){ - tree = new Tree(stack.getTagCompound().getCompoundTag("ContainedTree")); + IAlleleTreeSpecies treeSpecies = BlockPile.getTreeSpecies(stack); + if (treeSpecies == null) { + treeSpecies = (IAlleleTreeSpecies) TreeManager.treeRoot.getDefaultTemplate()[TreeManager.treeRoot.getSpeciesChromosomeType().ordinal()]; } - if (tree == null) { - tree = TreeManager.treeRoot.templateAsIndividual(TreeManager.treeRoot.getDefaultTemplate()); - } - return bakeModel(tree, true); + return bakeModel(treeSpecies, true); } } diff --git a/src/main/java/forestry/arboriculture/multiblock/CharcoalPileController.java b/src/main/java/forestry/arboriculture/multiblock/CharcoalPileController.java index a2f950ca2..f43995658 100644 --- a/src/main/java/forestry/arboriculture/multiblock/CharcoalPileController.java +++ b/src/main/java/forestry/arboriculture/multiblock/CharcoalPileController.java @@ -4,13 +4,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import net.minecraft.block.state.IBlockState; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - import forestry.api.arboriculture.EnumPileType; +import forestry.api.arboriculture.IWoodProvider; import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.multiblock.ICharcoalPileComponent; @@ -28,6 +23,11 @@ import forestry.core.network.DataOutputStreamForestry; import forestry.core.proxy.Proxies; import forestry.core.utils.Log; import forestry.core.utils.Translator; +import net.minecraft.block.state.IBlockState; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public class CharcoalPileController extends RectangularMultiblockControllerBase implements ICharcoalPileControllerInternal { @@ -115,11 +115,12 @@ public class CharcoalPileController extends RectangularMultiblockControllerBase if(woodBurnTime == 0){ int comps = 0; int newBurnTime = 0; - for(IMultiblockComponent part : connectedParts){ + for (IMultiblockComponent part : connectedParts) { ICharcoalPileComponent comp = (ICharcoalPileComponent) part; - if(comp.getTree() != null){ + if (comp.getTreeSpecies() != null) { comps++; - newBurnTime+= comp.getTree().getGenome().getCombustibility() * 1000; + IWoodProvider woodProvider = comp.getTreeSpecies().getWoodProvider(); + newBurnTime += woodProvider.getCombustibility() * 1000; } } woodBurnTime = newBurnTime / comps; diff --git a/src/main/java/forestry/arboriculture/render/CharcoalPileRenderer.java b/src/main/java/forestry/arboriculture/render/CharcoalPileRenderer.java index da8d22681..bdd6f7c6d 100644 --- a/src/main/java/forestry/arboriculture/render/CharcoalPileRenderer.java +++ b/src/main/java/forestry/arboriculture/render/CharcoalPileRenderer.java @@ -12,18 +12,10 @@ package forestry.arboriculture.render; import javax.annotation.Nonnull; -import static forestry.arboriculture.multiblock.EnumPilePosition.BACK; -import static forestry.arboriculture.multiblock.EnumPilePosition.CORNER_BACK_LEFT; -import static forestry.arboriculture.multiblock.EnumPilePosition.CORNER_BACK_RIGHT; -import static forestry.arboriculture.multiblock.EnumPilePosition.FRONT; -import static forestry.arboriculture.multiblock.EnumPilePosition.CORNER_FRONT_LEFT; -import static forestry.arboriculture.multiblock.EnumPilePosition.CORNER_FRONT_RIGHT; -import static forestry.arboriculture.multiblock.EnumPilePosition.SIDE_LEFT; -import static forestry.arboriculture.multiblock.EnumPilePosition.SIDE_RIGHT; +import static forestry.arboriculture.multiblock.EnumPilePosition.*; import forestry.api.arboriculture.EnumPileType; import forestry.api.arboriculture.IAlleleTreeSpecies; -import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.TreeManager; import forestry.arboriculture.blocks.BlockPile; import forestry.arboriculture.multiblock.EnumPilePosition; @@ -67,11 +59,10 @@ public class CharcoalPileRenderer extends TileEntitySpecialRenderer { boolean isOnTop = logic.getController().getMaximumCoord().getY() == pile.getPos().getY(); // TODO Add brightness to the textures. int brightness = state.getPackedLightmapCoords(pile.getWorld(), pile.getPos()); - ITree tree = pile.getNextWoodPile(); - if (tree == null) { - tree = TreeManager.treeRoot.templateAsIndividual(TreeManager.treeRoot.getDefaultTemplate()); + IAlleleTreeSpecies treeSpecies = pile.getNextWoodPile(); + if (treeSpecies == null) { + treeSpecies = (IAlleleTreeSpecies) TreeManager.treeRoot.getDefaultTemplate()[TreeManager.treeRoot.getSpeciesChromosomeType().ordinal()]; } - IAlleleTreeSpecies treeSpecies = tree.getGenome().getPrimary(); TextureAtlasSprite dirtSprite; if(pile.getPileType() == EnumPileType.ASH){ dirtSprite = TextureManager.registerSprite(new ResourceLocation("forestry:blocks/ash")); diff --git a/src/main/java/forestry/arboriculture/render/PileParticleCallback.java b/src/main/java/forestry/arboriculture/render/PileParticleCallback.java index 63a7ff682..2a76bf0c4 100644 --- a/src/main/java/forestry/arboriculture/render/PileParticleCallback.java +++ b/src/main/java/forestry/arboriculture/render/PileParticleCallback.java @@ -1,18 +1,17 @@ package forestry.arboriculture.render; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.particle.ParticleDigging; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - import forestry.api.arboriculture.EnumPileType; import forestry.arboriculture.blocks.BlockPile; import forestry.arboriculture.tiles.TilePile; import forestry.core.render.ParticleHelper; import forestry.core.render.TextureManager; import forestry.core.tiles.TileUtil; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.particle.ParticleDigging; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public class PileParticleCallback extends ParticleHelper.DefaultCallback{ @@ -25,14 +24,14 @@ public class PileParticleCallback extends ParticleHelper.DefaultCallback getPlantType() { + public EnumPlantType getPlantType() { ITree tree = getTree(); if (tree == null) { - return EnumSet.noneOf(EnumPlantType.class); + return EnumPlantType.Plains; } - return tree.getPlantTypes(); + return tree.getGenome().getPrimary().getPlantType(); } @Override diff --git a/src/main/java/forestry/arboriculture/tiles/TilePile.java b/src/main/java/forestry/arboriculture/tiles/TilePile.java index 702b9eb22..bcb03c216 100644 --- a/src/main/java/forestry/arboriculture/tiles/TilePile.java +++ b/src/main/java/forestry/arboriculture/tiles/TilePile.java @@ -2,20 +2,9 @@ package forestry.arboriculture.tiles; import javax.annotation.Nonnull; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - import forestry.api.arboriculture.EnumPileType; -import forestry.api.arboriculture.ITree; -import forestry.api.arboriculture.TreeManager; -import forestry.api.genetics.IAllele; +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.genetics.AlleleManager; import forestry.api.multiblock.ICharcoalPileComponent; import forestry.api.multiblock.IMultiblockController; import forestry.arboriculture.PluginArboriculture; @@ -25,11 +14,18 @@ import forestry.arboriculture.multiblock.EnumPilePosition; import forestry.arboriculture.multiblock.MultiblockLogicCharcoalPile; import forestry.core.multiblock.MultiblockTileEntityForestry; import forestry.core.tiles.TileUtil; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class TilePile extends MultiblockTileEntityForestry implements ICharcoalPileComponent{ - @Nonnull - private ITree containedTree; + private IAlleleTreeSpecies treeSpecies; @SideOnly(Side.CLIENT) private BlockPos woodPos; @@ -53,7 +49,7 @@ public class TilePile extends MultiblockTileEntityForestry chromosomeClass) { - if (primary == null) { - Log.warning("Missing primary allele: {}", this); - return true; - } - - if (!chromosomeClass.isInstance(primary)) { - Log.warning("Wrong primary allele for: {}. Should be: {}", this, chromosomeClass.getSimpleName()); - return true; - } - - if (secondary == null) { - Log.warning("Missing secondary allele: {}", this); - return true; - } - - if (!chromosomeClass.isInstance(secondary)) { - Log.warning("Wrong secondary allele for: {}. Should be: {}", this, chromosomeClass.getSimpleName()); - return true; - } - - return false; - } - /* HELPER FUNCTIONS */ public static IChromosome inheritChromosome(Random rand, IChromosome parent1, IChromosome parent2) { diff --git a/src/main/java/forestry/core/genetics/Genome.java b/src/main/java/forestry/core/genetics/Genome.java index af5269d0a..75c6bcd87 100755 --- a/src/main/java/forestry/core/genetics/Genome.java +++ b/src/main/java/forestry/core/genetics/Genome.java @@ -10,23 +10,20 @@ ******************************************************************************/ package forestry.core.genetics; -import com.google.common.base.Objects; - import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.Arrays; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - +import com.google.common.base.Objects; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; import forestry.api.genetics.IChromosome; import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IGenome; import forestry.api.genetics.ISpeciesRoot; -import forestry.core.config.Config; -import forestry.core.utils.Log; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; public abstract class Genome implements IGenome { @@ -115,15 +112,12 @@ public abstract class Genome implements IGenome { * Quickly gets the species without loading the whole genome. * We need this because the client uses the species for rendering. */ - public static IAlleleSpecies getSpeciesDirectly(ItemStack itemStack) { + @Nullable + public static IAlleleSpecies getSpeciesDirectly(@Nonnull ISpeciesRoot speciesRoot, @Nonnull ItemStack itemStack) { NBTTagCompound nbtTagCompound = itemStack.getTagCompound(); if (nbtTagCompound == null) { return null; } - return getSpeciesDirectly(nbtTagCompound); - } - - public static IAlleleSpecies getSpeciesDirectly(@Nonnull NBTTagCompound nbtTagCompound) { NBTTagCompound genomeNBT = nbtTagCompound.getCompoundTag("Genome"); if (genomeNBT == null) { @@ -136,7 +130,7 @@ public abstract class Genome implements IGenome { } NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(0); - Chromosome chromosome = new Chromosome(chromosomeNBT); + Chromosome chromosome = Chromosome.create(null, null, speciesRoot.getSpeciesChromosomeType(), chromosomeNBT); IAllele activeAllele = chromosome.getActiveAllele(); if (!(activeAllele instanceof IAlleleSpecies)) { @@ -170,23 +164,21 @@ public abstract class Genome implements IGenome { NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10); IChromosome[] chromosomes = new IChromosome[speciesRoot.getDefaultTemplate().length]; + String primarySpeciesUid = null; + String secondarySpeciesUid = null; + for (int i = 0; i < chromosomesNBT.tagCount(); i++) { NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(i); byte chromosomeOrdinal = chromosomeNBT.getByte(SLOT_TAG); if (chromosomeOrdinal >= 0 && chromosomeOrdinal < chromosomes.length) { - Chromosome chromosome = new Chromosome(chromosomeNBT); + IChromosomeType chromosomeType = speciesRoot.getKaryotype()[chromosomeOrdinal]; + Chromosome chromosome = Chromosome.create(primarySpeciesUid, secondarySpeciesUid, chromosomeType, chromosomeNBT); chromosomes[chromosomeOrdinal] = chromosome; - IChromosomeType chromosomeType = speciesRoot.getKaryotype()[chromosomeOrdinal]; - if (chromosome.hasInvalidAlleles(chromosomeType.getAlleleClass())) { - if (Config.clearInvalidChromosomes) { - Log.warning("Found Chromosome with invalid Alleles. Config is set to clear invalid chromosomes, replacing with the default."); - IAllele[] defaultTemplate = speciesRoot.getDefaultTemplate(); - return speciesRoot.templateAsChromosomes(defaultTemplate); - } else { - throw new RuntimeException("Found Chromosome with invalid Alleles.\nNBTTagCompound: " + chromosomesNBT + "\nSee config option \"genetics.clear.invalid.chromosomes\".\nMissing: " + chromosomeNBT); - } + if (chromosomeOrdinal == speciesRoot.getSpeciesChromosomeType().ordinal()) { + primarySpeciesUid = chromosome.getPrimaryAllele().getUID(); + secondarySpeciesUid = chromosome.getSecondaryAllele().getUID(); } } } diff --git a/src/main/java/forestry/core/genetics/ItemResearchNote.java b/src/main/java/forestry/core/genetics/ItemResearchNote.java index 74695b9c3..48e29fda1 100755 --- a/src/main/java/forestry/core/genetics/ItemResearchNote.java +++ b/src/main/java/forestry/core/genetics/ItemResearchNote.java @@ -14,19 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.EnumActionResult; -import net.minecraft.util.EnumHand; -import net.minecraft.util.text.TextComponentTranslation; -import net.minecraft.util.text.TextFormatting; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; @@ -38,6 +26,16 @@ import forestry.core.items.ItemForestry; import forestry.core.proxy.Proxies; import forestry.core.utils.PlayerUtil; import forestry.core.utils.Translator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ActionResult; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; +import net.minecraft.util.text.TextComponentTranslation; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; public class ItemResearchNote extends ItemForestry { @@ -94,7 +92,7 @@ public class ItemResearchNote extends ItemForestry { String species2 = encoded.getAllele1().getName(); String mutationChanceKey = EnumMutateChance.rateChance(encoded.getBaseChance()).toString().toLowerCase(Locale.ENGLISH); String mutationChance = Translator.translateToLocal("for.researchNote.chance." + mutationChanceKey); - String speciesResult = encoded.getTemplate()[root.getKaryotypeKey().ordinal()].getName(); + String speciesResult = encoded.getTemplate()[root.getSpeciesChromosomeType().ordinal()].getName(); tooltips.add(Translator.translateToLocal("for.researchNote.discovery.0")); tooltips.add(Translator.translateToLocal("for.researchNote.discovery.1").replace("%SPEC1", species1).replace("%SPEC2", species2)); @@ -147,7 +145,7 @@ public class ItemResearchNote extends ItemForestry { IAlleleSpecies species0 = encoded.getAllele0(); IAlleleSpecies species1 = encoded.getAllele1(); - IAlleleSpecies speciesResult = (IAlleleSpecies) encoded.getTemplate()[root.getKaryotypeKey().ordinal()]; + IAlleleSpecies speciesResult = (IAlleleSpecies) encoded.getTemplate()[root.getSpeciesChromosomeType().ordinal()]; tracker.registerSpecies(species0); tracker.registerSpecies(species1); diff --git a/src/main/java/forestry/core/genetics/alleles/AlleleSpecies.java b/src/main/java/forestry/core/genetics/alleles/AlleleSpecies.java index ae71407fb..6306070ac 100644 --- a/src/main/java/forestry/core/genetics/alleles/AlleleSpecies.java +++ b/src/main/java/forestry/core/genetics/alleles/AlleleSpecies.java @@ -14,12 +14,7 @@ import javax.annotation.Nonnull; import java.util.Collection; import java.util.Map; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - import forestry.api.core.EnumHumidity; import forestry.api.core.EnumTemperature; import forestry.api.genetics.AlleleManager; @@ -33,6 +28,9 @@ import forestry.apiculture.items.ItemRegistryApiculture; import forestry.core.utils.GeneticsUtil; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Translator; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; public abstract class AlleleSpecies extends Allele implements IAlleleSpeciesBuilder, IAlleleSpecies { private final String binomial; @@ -103,7 +101,7 @@ public abstract class AlleleSpecies extends Allele implements IAlleleSpeciesBuil if (complexityOverride != null) { return complexityOverride; } - return GeneticsUtil.getResearchComplexity(this, getRoot().getKaryotypeKey()); + return GeneticsUtil.getResearchComplexity(this, getRoot().getSpeciesChromosomeType()); } @Override diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java index fd4f8e933..80cac16b8 100755 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyGenome.java @@ -10,8 +10,6 @@ ******************************************************************************/ package forestry.lepidopterology.genetics; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IAlleleFloat; import forestry.api.genetics.IAlleleFlowers; @@ -29,6 +27,8 @@ import forestry.api.lepidopterology.IButterflyGenome; import forestry.core.genetics.Genome; import forestry.core.genetics.alleles.AlleleBoolean; import forestry.core.genetics.alleles.AlleleTolerance; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; public class ButterflyGenome extends Genome implements IButterflyGenome { @@ -46,8 +46,8 @@ public class ButterflyGenome extends Genome implements IButterflyGenome { if (!ButterflyManager.butterflyRoot.isMember(itemStack)) { return null; } - - IAlleleSpecies species = getSpeciesDirectly(itemStack); + + IAlleleSpecies species = getSpeciesDirectly(ButterflyManager.butterflyRoot, itemStack); if (species instanceof IAlleleButterflySpecies) { return (IAlleleButterflySpecies) species; } diff --git a/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java b/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java index 46bfece1e..c9aa9cb64 100644 --- a/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java +++ b/src/main/java/forestry/lepidopterology/genetics/ButterflyRoot.java @@ -16,17 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Map.Entry; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - import com.mojang.authlib.GameProfile; - import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlyzerPlugin; @@ -50,6 +40,14 @@ import forestry.core.utils.EntityUtil; import forestry.lepidopterology.PluginLepidopterology; import forestry.lepidopterology.entities.EntityButterfly; import forestry.lepidopterology.tiles.TileCocoon; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { @@ -315,7 +313,7 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot { } @Override - public IChromosomeType getKaryotypeKey() { + public IChromosomeType getSpeciesChromosomeType() { return EnumButterflyChromosome.SPECIES; }