2017-01-31 18:49:42 +01:00
/ *
2017-02-04 16:48:22 +01:00
* This file ( " ReedFarmerBehavior.java " ) is part of the Actually Additions mod for Minecraft .
2017-01-31 18:49:42 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http : //ellpeck.de/actaddlicense
* View the source code at https : //github.com/Ellpeck/ActuallyAdditions
*
* © 2015 - 2017 Ellpeck
* /
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer ;
2017-02-22 13:28:53 +01:00
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult ;
2017-01-31 18:49:42 +01:00
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior ;
import de.ellpeck.actuallyadditions.api.internal.IFarmer ;
import net.minecraft.block.Block ;
import net.minecraft.block.BlockReed ;
import net.minecraft.block.state.IBlockState ;
import net.minecraft.init.Blocks ;
import net.minecraft.init.Items ;
import net.minecraft.item.ItemStack ;
import net.minecraft.util.math.BlockPos ;
import net.minecraft.world.World ;
import java.util.List ;
public class ReedFarmerBehavior implements IFarmerBehavior {
@Override
2017-02-22 13:28:53 +01:00
public FarmerResult tryPlantSeed ( ItemStack seed , World world , BlockPos pos , IFarmer farmer ) {
2017-01-31 18:49:42 +01:00
int use = 250 ;
if ( farmer . getEnergy ( ) > = use ) {
if ( seed . getItem ( ) = = Items . REEDS ) {
if ( Blocks . REEDS . canPlaceBlockAt ( world , pos ) ) {
world . setBlockState ( pos , Blocks . REEDS . getDefaultState ( ) , 2 ) ;
farmer . extractEnergy ( use ) ;
2017-02-22 13:28:53 +01:00
return FarmerResult . SUCCESS ;
2017-01-31 18:49:42 +01:00
}
2017-02-22 13:28:53 +01:00
return FarmerResult . STOP_PROCESSING ;
2017-01-31 18:49:42 +01:00
}
}
2017-02-22 13:28:53 +01:00
return FarmerResult . FAIL ;
2017-01-31 18:49:42 +01:00
}
@Override
2017-02-22 13:28:53 +01:00
public FarmerResult tryHarvestPlant ( World world , BlockPos pos , IFarmer farmer ) {
2017-01-31 18:49:42 +01:00
int use = 250 ;
if ( farmer . getEnergy ( ) > = use ) {
IBlockState state = world . getBlockState ( pos ) ;
if ( state . getBlock ( ) instanceof BlockReed ) {
2017-02-22 13:28:53 +01:00
FarmerResult result = FarmerResult . STOP_PROCESSING ;
2017-01-31 18:49:42 +01:00
for ( int i = 2 ; i > = 1 ; - - i ) {
if ( farmer . getEnergy ( ) > = use ) {
BlockPos up = pos . up ( i ) ;
IBlockState upState = world . getBlockState ( up ) ;
if ( upState . getBlock ( ) instanceof BlockReed ) {
List < ItemStack > drops = upState . getBlock ( ) . getDrops ( world , up , upState , 0 ) ;
if ( drops ! = null & & ! drops . isEmpty ( ) ) {
if ( farmer . addToOutputInventory ( drops , false ) ) {
2017-02-22 13:28:53 +01:00
world . playEvent ( 2001 , up , Block . getStateId ( upState ) ) ;
2017-01-31 18:49:42 +01:00
world . setBlockToAir ( up ) ;
farmer . extractEnergy ( use ) ;
farmer . addToOutputInventory ( drops , true ) ;
2017-02-22 13:28:53 +01:00
2017-07-26 22:51:42 +02:00
result = FarmerResult . STOP_PROCESSING ; //Success no longer makes it not replant, and the plant logic seems sketchy right after harvesting. This works tho.
2017-01-31 18:49:42 +01:00
}
}
}
}
}
2017-02-22 13:28:53 +01:00
return result ;
2017-01-31 18:49:42 +01:00
}
}
2017-02-22 13:28:53 +01:00
return FarmerResult . FAIL ;
}
@Override
public int getPriority ( ) {
return 0 ;
2017-01-31 18:49:42 +01:00
}
}