Add ILeafProvider

This commit is contained in:
Nedelosk committed 2017-01-24 11:11:24 +01:00
1 parent 6cb3b73200
commit 7b340fdb49
8 files changed
+119 -10

No files matched your search

@@ -43,6 +43,8 @@ public interface IAlleleTreeSpecies extends IAlleleSpecies, IAlleleProperty<IAll
String getModID();
IWoodProvider getWoodProvider();
ILeafProvider getLeafProvider();
/* MODELS AND OVERRIDES */
@SideOnly(Side.CLIENT)
@@ -0,0 +1,16 @@
/*******************************************************************************
* Copyright 2011-2014 SirSengir
*
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
******************************************************************************/
package forestry.api.arboriculture;
import net.minecraft.item.ItemStack;
public interface ILeafProvider {
void init(IAlleleTreeSpecies treeSpecies);
ItemStack getDecorativeLeaves();
}
@@ -31,6 +31,27 @@ public interface ITreeFactory {
*/
IAlleleTreeSpeciesBuilder createSpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, boolean dominant, IClassification branch, String binomial, String modID, ILeafSpriteProvider leafSpriteProvider, IGermlingModelProvider germlingModelProvider, IWoodProvider woodProvider, ITreeGenerator generator);
/**
* Creates a new tree species.
* Automatically registered with AlleleManager.alleleRegistry.registerAllele()
* See IAlleleTreeSpeciesBuilder and IAlleleSpeciesBuilder for adding additional properties to the returned species.
*
* @param uid Unique Identifier for this species
* @param unlocalizedName Unlocalized name for this species
* @param authority Authority for the binomial name, e.g. "Sengir" on species of base Forestry.
* @param unlocalizedDescription Unlocalized description for this species
* @param dominant Whether this species is genetically dominant (false means it is recessive)
* @param branch Classification of this species
* @param binomial Binomial name of the species sans genus. "humboldti" will have the bee species flavour name be "Apis humboldti". Feel free to use fun names or null.
* @param modID The modID from the mod of the species
* @param leafSpriteProvider The leaf sprite provider for this species
* @param germlingModelProvider The germling model provider for this species
* @param woodProvider The wood texture provider. It is used to get wood textures for the charcoal pile.
* @param generator The tree generator
* @return a new tree species allele.
*/
IAlleleTreeSpeciesBuilder createSpecies(String uid, String unlocalizedName, String authority, String unlocalizedDescription, boolean dominant, IClassification branch, String binomial, String modID, ILeafSpriteProvider leafSpriteProvider, IGermlingModelProvider germlingModelProvider, IWoodProvider woodProvider, ITreeGenerator generator, ILeafProvider leafProvider);
/**
* Get one of the built-in Forestry leaf types. Default type is deciduous.
*/
@@ -6,6 +6,7 @@
package forestry.api.arboriculture;
import forestry.api.genetics.IGenome;
import net.minecraft.item.ItemStack;
public interface ITreeGenome extends IGenome {
@@ -37,4 +38,10 @@ public interface ITreeGenome extends IGenome {
int getGirth();
IAlleleLeafEffect getEffect();
/**
*
* @return A ItemStack that is used in getPickBlock of the leave block.
*/
ItemStack getDecorativeLeaves();
}
@@ -203,23 +203,23 @@ public class BlockForestryLeaves extends BlockLeaves implements ITileEntityProvi
return ItemStack.EMPTY;
}
String speciesUid = tree.getGenome().getPrimary().getUID();
return PluginArboriculture.getBlocks().getDecorativeLeaves(speciesUid);
return tree.getGenome().getDecorativeLeaves();
}
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) {
String speciesUid = TreeDefinition.Oak.getUID();
ITree tree = null;
TileLeaves leaves = TileUtil.getTile(world, pos, TileLeaves.class);
if (leaves != null) {
ITree tree = leaves.getTree();
if (tree != null) {
speciesUid = tree.getGenome().getPrimary().getUID();
}
tree = leaves.getTree();
}
if(tree == null){
tree = TreeDefinition.Oak.getIndividual();
}
ItemStack decorativeLeaves = PluginArboriculture.getBlocks().getDecorativeLeaves(speciesUid);
ItemStack decorativeLeaves = tree.getGenome().getDecorativeLeaves();
if (decorativeLeaves.isEmpty()) {
return Collections.emptyList();
} else {
@@ -0,0 +1,31 @@
package forestry.arboriculture.genetics;
import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.ILeafProvider;
import forestry.api.genetics.IAllele;
import forestry.arboriculture.PluginArboriculture;
import net.minecraft.item.ItemStack;
public class LeafProvider implements ILeafProvider {
private IAlleleTreeSpecies treeSpecies;
public LeafProvider() {
}
@Override
public void init(IAlleleTreeSpecies treeSpecies) {
this.treeSpecies = treeSpecies;
}
@Override
public ItemStack getDecorativeLeaves() {
IAllele allele = treeSpecies;
if(allele == null){
allele = TreeDefinition.Oak.getTemplate()[EnumTreeChromosome.SPECIES.ordinal()];
}
return PluginArboriculture.getBlocks().getDecorativeLeaves(allele.getUID());
}
}
@@ -99,6 +99,11 @@ public class TreeGenome extends Genome implements ITreeGenome {
public IAlleleLeafEffect getEffect() {
return (IAlleleLeafEffect) getActiveAllele(EnumTreeChromosome.EFFECT);
}
@Override
public ItemStack getDecorativeLeaves() {
return getPrimary().getLeafProvider().getDecorativeLeaves();
}
@Override
public ISpeciesRoot getSpeciesRoot() {
@@ -18,6 +18,7 @@ import forestry.api.arboriculture.EnumTreeChromosome;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IAlleleTreeSpeciesBuilder;
import forestry.api.arboriculture.IGermlingModelProvider;
import forestry.api.arboriculture.ILeafProvider;
import forestry.api.arboriculture.ILeafSpriteProvider;
import forestry.api.arboriculture.ITreeGenerator;
import forestry.api.arboriculture.ITreeRoot;
@@ -27,6 +28,7 @@ import forestry.api.core.IModelManager;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IClassification;
import forestry.api.genetics.IFruitFamily;
import forestry.arboriculture.genetics.LeafProvider;
import forestry.core.genetics.alleles.AlleleSpecies;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
@@ -42,7 +44,24 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci
private final List<IFruitFamily> fruits = new ArrayList<>();
private final String modID;
private EnumPlantType nativeType = EnumPlantType.Plains;
private final ILeafProvider leafProvider;
public AlleleTreeSpecies(
String uid,
String unlocalizedName,
String authority,
String unlocalizedDescription,
boolean isDominant,
IClassification branch,
String binomial,
String modID,
ILeafSpriteProvider leafSpriteProvider,
IGermlingModelProvider germlingModelProvider,
IWoodProvider woodProvider,
ITreeGenerator generator) {
this(uid, unlocalizedName, authority, unlocalizedDescription, isDominant, branch, binomial, modID, leafSpriteProvider, germlingModelProvider, woodProvider, generator, new LeafProvider());
}
public AlleleTreeSpecies(
String uid,
String unlocalizedName,
@@ -55,13 +74,15 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci
ILeafSpriteProvider leafIconProvider,
IGermlingModelProvider germlingModelProvider,
IWoodProvider woodProvider,
ITreeGenerator generator) {
ITreeGenerator generator,
ILeafProvider leafProvider) {
super(uid, unlocalizedName, authority, unlocalizedDescription, isDominant, branch, binomial);
this.generator = generator;
this.germlingModelProvider = germlingModelProvider;
this.woodProvider = woodProvider;
this.leafSpriteProvider = leafIconProvider;
this.leafProvider = leafProvider;
this.modID = modID;
}
@@ -69,6 +90,7 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci
@Override
public IAlleleTreeSpecies build() {
AlleleManager.alleleRegistry.registerAllele(this, EnumTreeChromosome.SPECIES);
leafProvider.init(this);
return this;
}
@@ -138,6 +160,11 @@ public class AlleleTreeSpecies extends AlleleSpecies implements IAlleleTreeSpeci
return woodProvider;
}
@Override
public ILeafProvider getLeafProvider() {
return leafProvider;
}
@Override
public String getModID() {
return modID;