mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Add some more checks to the Farmer
This commit is contained in:
parent
cd019863bf
commit
11b7ecb172
1 changed files with 17 additions and 4 deletions
|
@ -18,6 +18,7 @@ import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.init.SoundEvents;
|
import net.minecraft.init.SoundEvents;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
@ -108,7 +109,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom
|
||||||
Block farmlandBlock = farmlandState.getBlock();
|
Block farmlandBlock = farmlandState.getBlock();
|
||||||
|
|
||||||
if(farmlandBlock instanceof BlockFarmland){
|
if(farmlandBlock instanceof BlockFarmland){
|
||||||
IBlockState toPlant = this.getFirstPlantFromSlots(plant);
|
IBlockState toPlant = this.getFirstPlantablePlantFromSlots(plant);
|
||||||
if(toPlant != null){
|
if(toPlant != null){
|
||||||
this.worldObj.setBlockState(plant, toPlant, 2);
|
this.worldObj.setBlockState(plant, toPlant, 2);
|
||||||
didSomething = true;
|
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++){
|
for(int i = 0; i < 6; i++){
|
||||||
ItemStack stack = this.slots[i];
|
ItemStack stack = this.slots[i];
|
||||||
if(stack != null){
|
if(stack != null){
|
||||||
|
IPlantable plantable = null;
|
||||||
|
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if(item instanceof IPlantable){
|
if(item instanceof IPlantable){
|
||||||
IBlockState state = ((IPlantable)item).getPlant(this.worldObj, pos);
|
plantable = (IPlantable)item;
|
||||||
if(state != null){
|
}
|
||||||
|
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);
|
this.decrStackSize(i, 1);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue