diff --git a/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java b/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java index fee2c0c99..2c209e9e9 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockForestryLeaves.java @@ -153,12 +153,17 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP List prod = new ArrayList<>(); TileLeaves tile = TileUtil.getTile(world, pos, TileLeaves.class); - if (tile == null || tile.getTree() == null) { + if (tile == null) { + return prod; + } + + ITree tree = tile.getTree(); + if (tree == null) { return prod; } // Add saplings - ITree[] saplings = tile.getTree().getSaplings((World) world, playerProfile, pos, saplingModifier); + ITree[] saplings = tree.getSaplings((World) world, playerProfile, pos, saplingModifier); for (ITree sapling : saplings) { if (sapling != null) { @@ -168,7 +173,7 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP // Add fruits if (tile.hasFruit()) { - prod.addAll(tile.getTree().produceStacks((World) world, pos, tile.getRipeningTime())); + prod.addAll(tree.produceStacks((World) world, pos, tile.getRipeningTime())); } return prod; @@ -180,7 +185,12 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP if (leaves == null) { return null; } + ITree tree = leaves.getTree(); + if (tree == null) { + return null; + } + String speciesUid = tree.getGenome().getPrimary().getUID(); return PluginArboriculture.blocks.getDecorativeLeaves(speciesUid); } @@ -196,7 +206,12 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP if (leaves == null) { return null; } + ITree tree = leaves.getTree(); + if (tree == null) { + return null; + } + String speciesUid = tree.getGenome().getPrimary().getUID(); return Collections.singletonList(PluginArboriculture.blocks.getDecorativeLeaves(speciesUid)); } diff --git a/src/main/java/forestry/arboriculture/blocks/BlockSapling.java b/src/main/java/forestry/arboriculture/blocks/BlockSapling.java index ee373adba..7390f0137 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockSapling.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockSapling.java @@ -34,6 +34,7 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.arboriculture.EnumGermlingType; +import forestry.api.arboriculture.ITree; import forestry.api.arboriculture.TreeManager; import forestry.api.core.IItemModelRegister; import forestry.api.core.IModelManager; @@ -132,11 +133,13 @@ public class BlockSapling extends BlockTreeContainer implements IGrowable, IStat if (tile == null) { return false; } - if (tile.getTree() == null) { + + ITree tree = tile.getTree(); + if (tree == null) { return false; } - return tile.getTree().canStay(world, pos); + return tree.canStay(world, pos); } @Override diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index 688fc579d..b3370671b 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -218,6 +218,9 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru private int determineFruitColour() { ITree tree = getTree(); + if (tree == null) { + tree = TreeDefinition.Cherry.getIndividual(); + } ITreeGenome genome = tree.getGenome(); IFruitProvider fruit = genome.getFruitProvider(); return fruit.getColour(genome, worldObj, getPos(), getRipeningTime()); @@ -255,32 +258,35 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru /* IPOLLINATABLE */ @Override public EnumSet getPlantType() { - if (getTree() == null) { + ITree tree = getTree(); + if (tree == null) { return EnumSet.noneOf(EnumPlantType.class); } - return getTree().getPlantTypes(); + return tree.getPlantTypes(); } @Override public boolean canMateWith(ITree individual) { - if (getTree() == null) { + ITree tree = getTree(); + if (tree == null) { return false; } - if (getTree().getMate() != null) { + if (tree.getMate() != null) { return false; } - return !getTree().isGeneticEqual(individual); + return !tree.isGeneticEqual(individual); } @Override public void mateWith(ITree individual) { - if (getTree() == null) { + ITree tree = getTree(); + if (tree == null) { return; } - getTree().mate(individual); + tree.mate(individual); worldObj.markBlockForUpdate(getPos()); } diff --git a/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java b/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java index 732f00190..a91d7378d 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java +++ b/src/main/java/forestry/arboriculture/tiles/TileTreeContainer.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.arboriculture.tiles; +import javax.annotation.Nullable; import java.io.IOException; import net.minecraft.block.Block; @@ -41,7 +42,9 @@ import forestry.core.utils.PlayerUtil; */ public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnable { + @Nullable private ITree containedTree; + @Nullable private GameProfile owner; /* SAVING & LOADING */ @@ -108,6 +111,7 @@ public abstract class TileTreeContainer extends TileEntity implements IStreamabl } } + @Nullable public ITree getTree() { return this.containedTree; }