Fix crash from waila "harvesting" tree leaves before it syncs

This commit is contained in:
mezz committed 2016-04-29 00:06:19 -07:00
1 parent 641dea32ac
commit 9e33648920
4 files changed
+40 -12

No files matched your search

@@ -153,12 +153,17 @@ public class BlockForestryLeaves extends BlockLeavesBase implements ITileEntityP
List<ItemStack> 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));
}
@@ -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
@@ -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<EnumPlantType> 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());
}
@@ -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;
}