diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java index 35fdd9c97..8f7ceb122 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java @@ -65,7 +65,7 @@ public class ContainerFarmer extends Container{ //Other Slots in Inventory excluded if(slot >= inventoryStart){ //Shift from Inventory - if(newStack.getItem() instanceof IPlantable){ + if(TileEntityFarmer.getPlantableFromStack(newStack) != null){ if(!this.mergeItemStack(newStack, 0, 6, false)){ return StackUtil.getNull(); } 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 0d7d8a118..fb4017729 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -29,6 +29,7 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.IPlantable; +import java.util.ArrayList; import java.util.List; public class TileEntityFarmer extends TileEntityInventoryBase implements ICustomEnergyReceiver{ @@ -93,10 +94,31 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom if(plantBlock instanceof BlockCrops){ if(((BlockCrops)plantBlock).isMaxAge(plantState)){ - List drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0); + List seeds = new ArrayList(); + List other = new ArrayList(); - if(WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, false, true)){ - WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, true, true); + List drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0); + for(ItemStack stack : drops){ + if(getPlantableFromStack(stack) != null){ + seeds.add(stack); + } + else{ + other.add(stack); + } + } + + boolean putSeeds = true; + if(!WorldUtil.addToInventory(this, 0, 6, seeds, EnumFacing.UP, false, true)){ + other.addAll(seeds); + putSeeds = false; + } + + if(WorldUtil.addToInventory(this, 6, 12, other, EnumFacing.UP, false, true)){ + WorldUtil.addToInventory(this, 6, 12, other, EnumFacing.UP, true, true); + + if(putSeeds){ + WorldUtil.addToInventory(this, 0, 6, seeds, EnumFacing.UP, true, true); + } this.worldObj.playEvent(2001, plant, Block.getStateId(plantState)); this.worldObj.setBlockToAir(plant); @@ -152,19 +174,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom for(int i = 0; i < 6; i++){ ItemStack stack = this.slots[i]; if(StackUtil.isValid(stack)){ - IPlantable plantable = null; - - Item item = stack.getItem(); - if(item instanceof IPlantable){ - plantable = (IPlantable)item; - } - else if(item instanceof ItemBlock){ - Block block = Block.getBlockFromItem(item); - if(block instanceof IPlantable){ - plantable = (IPlantable)block; - } - } - + IPlantable plantable = getPlantableFromStack(stack); if(plantable != null){ IBlockState state = plantable.getPlant(this.worldObj, pos); if(state != null && state.getBlock() instanceof BlockCrops && state.getBlock().canPlaceBlockAt(this.worldObj, pos)){ @@ -177,9 +187,23 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom return null; } + public static IPlantable getPlantableFromStack(ItemStack stack){ + Item item = stack.getItem(); + if(item instanceof IPlantable){ + return (IPlantable)item; + } + else if(item instanceof ItemBlock){ + Block block = Block.getBlockFromItem(item); + if(block instanceof IPlantable){ + return (IPlantable)block; + } + } + return null; + } + @Override public boolean isItemValidForSlot(int i, ItemStack stack){ - return i < 6 && StackUtil.isValid(stack) && stack.getItem() instanceof IPlantable; + return i < 6 && StackUtil.isValid(stack) && getPlantableFromStack(stack) != null; } @Override