From 11b7ecb172f0647a22582b7d6909c3742fcaa3d8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 1 Nov 2016 15:46:02 +0100 Subject: [PATCH] Add some more checks to the Farmer --- .../mod/tile/TileEntityFarmer.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java index 6939797da..1a42eff7d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -18,6 +18,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.SoundEvents; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; @@ -108,7 +109,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom Block farmlandBlock = farmlandState.getBlock(); if(farmlandBlock instanceof BlockFarmland){ - IBlockState toPlant = this.getFirstPlantFromSlots(plant); + IBlockState toPlant = this.getFirstPlantablePlantFromSlots(plant); if(toPlant != null){ this.worldObj.setBlockState(plant, toPlant, 2); didSomething = true; @@ -148,14 +149,26 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom } } - private IBlockState getFirstPlantFromSlots(BlockPos pos){ + private IBlockState getFirstPlantablePlantFromSlots(BlockPos pos){ for(int i = 0; i < 6; i++){ ItemStack stack = this.slots[i]; if(stack != null){ + IPlantable plantable = null; + Item item = stack.getItem(); if(item instanceof IPlantable){ - IBlockState state = ((IPlantable)item).getPlant(this.worldObj, pos); - if(state != null){ + plantable = (IPlantable)item; + } + else if(item instanceof ItemBlock){ + Block block = Block.getBlockFromItem(item); + if(block instanceof IPlantable){ + plantable = (IPlantable)block; + } + } + + if(plantable != null){ + IBlockState state = plantable.getPlant(this.worldObj, pos); + if(state != null && state.getBlock() instanceof BlockCrops && state.getBlock().canPlaceBlockAt(this.worldObj, pos)){ this.decrStackSize(i, 1); return state; }