Not everything is a BlockCrops

This commit is contained in:
Shadows_of_Fire 2018-01-31 01:46:37 -05:00
parent 0b02277006
commit c2209f0596
4 changed files with 53 additions and 53 deletions

View file

@ -86,6 +86,6 @@ public class CactusFarmerBehavior implements IFarmerBehavior{
@Override @Override
public int getPriority(){ public int getPriority(){
return 0; return 4;
} }
} }

View file

@ -43,27 +43,19 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
IBlockState state = world.getBlockState(pos); IBlockState state = world.getBlockState(pos);
Block block = state.getBlock(); Block block = state.getBlock();
if(world.isAirBlock(pos) || block.isReplaceable(world, pos)){ if(block.isReplaceable(world, pos)){
BlockPos farmland = pos.down(); BlockPos farmland = pos.down();
Block farmlandBlock = world.getBlockState(farmland).getBlock(); Block farmlandBlock = world.getBlockState(farmland).getBlock();
if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){
world.setBlockToAir(pos);
useHoeAt(world, farmland);
world.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
farmer.extractEnergy(use);
}
if(tryPlant(toPlant, world, pos)){ if(tryPlant(toPlant, world, pos)){
farmer.extractEnergy(use); farmer.extractEnergy(use);
return true; return true;
}
else{
if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){
useHoeAt(world, pos.down());
world.setBlockToAir(pos);
world.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
farmer.extractEnergy(use);
if(tryPlant(toPlant, world, pos)){
farmer.extractEnergy(use);
return true;
}
}
} }
} }
} }
@ -98,40 +90,48 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
if(block instanceof BlockCrops){ if(block instanceof BlockCrops){
if(((BlockCrops)block).isMaxAge(state)){ if(((BlockCrops)block).isMaxAge(state)){
List<ItemStack> seeds = new ArrayList<ItemStack>(); return doFarmerStuff(state, world, pos, farmer);
List<ItemStack> other = new ArrayList<ItemStack>();
NonNullList<ItemStack> drops = NonNullList.create();
block.getDrops(drops, world, pos, state, 0);
for(ItemStack stack : drops){
if(this.getPlantableFromStack(stack) != null){
seeds.add(stack);
}
else{
other.add(stack);
}
}
boolean putSeeds = true;
if(!farmer.addToSeedInventory(seeds, false)){
other.addAll(seeds);
putSeeds = false;
}
if(farmer.addToOutputInventory(other, false)){
farmer.addToOutputInventory(other, true);
if(putSeeds){
farmer.addToSeedInventory(seeds, true);
}
world.playEvent(2001, pos, Block.getStateId(state));
world.setBlockToAir(pos);
farmer.extractEnergy(use);
return FarmerResult.SUCCESS;
}
} }
} }
else if((BlockCrops.AGE).equals(block.getBlockState().getProperty("age"))) {
if(state.getValue(BlockCrops.AGE) >= 7) return doFarmerStuff(state, world, pos, farmer);
}
}
return FarmerResult.FAIL;
}
private FarmerResult doFarmerStuff(IBlockState state, World world, BlockPos pos, IFarmer farmer) {
List<ItemStack> seeds = new ArrayList<>();
List<ItemStack> other = new ArrayList<>();
NonNullList<ItemStack> drops = NonNullList.create();
state.getBlock().getDrops(drops, world, pos, state, 0);
for(ItemStack stack : drops){
if(this.getPlantableFromStack(stack) != null){
seeds.add(stack);
}
else{
other.add(stack);
}
}
boolean putSeeds = true;
if(!farmer.addToSeedInventory(seeds, false)){
other.addAll(seeds);
putSeeds = false;
}
if(farmer.addToOutputInventory(other, false)){
farmer.addToOutputInventory(other, true);
if(putSeeds){
farmer.addToSeedInventory(seeds, true);
}
world.playEvent(2001, pos, Block.getStateId(state));
world.setBlockToAir(pos);
farmer.extractEnergy(250);
return FarmerResult.SUCCESS;
} }
return FarmerResult.FAIL; return FarmerResult.FAIL;
} }
@ -146,7 +146,7 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
IPlantable plantable = this.getPlantableFromStack(stack); IPlantable plantable = this.getPlantableFromStack(stack);
if(plantable != null){ if(plantable != null){
IBlockState state = plantable.getPlant(world, pos); IBlockState state = plantable.getPlant(world, pos);
if(state != null && state.getBlock() instanceof BlockCrops){ if(state != null && state.getBlock() instanceof IGrowable){
return state; return state;
} }
} }

View file

@ -78,6 +78,6 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
@Override @Override
public int getPriority(){ public int getPriority(){
return 0; return 3;
} }
} }

View file

@ -80,6 +80,6 @@ public class ReedFarmerBehavior implements IFarmerBehavior{
@Override @Override
public int getPriority(){ public int getPriority(){
return 0; return 2;
} }
} }