2016-12-04 16:15:32 +01:00
|
|
|
/*
|
|
|
|
* This file ("NetherWartFarmerBehavior.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* 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
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-12-04 16:15:32 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
|
|
|
|
2017-02-22 13:28:53 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
2016-12-04 16:15:32 +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.BlockNetherWart;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2017-07-24 11:31:09 +02:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.NonNullList;
|
2016-12-04 16:15:32 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2017-07-24 11:31:09 +02:00
|
|
|
import net.minecraftforge.common.IPlantable;
|
2016-12-04 16:15:32 +01:00
|
|
|
|
|
|
|
public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
|
|
|
|
|
|
|
@Override
|
2017-02-22 13:28:53 +01:00
|
|
|
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
2016-12-04 16:15:32 +01:00
|
|
|
int use = 500;
|
|
|
|
if(farmer.getEnergy() >= use){
|
|
|
|
if(seed.getItem() == Items.NETHER_WART){
|
2017-07-24 11:31:09 +02:00
|
|
|
if(world.getBlockState(pos.down()).getBlock().canSustainPlant(world.getBlockState(pos.down()), world, pos.down(), EnumFacing.UP, (IPlantable) Items.NETHER_WART)){
|
2016-12-04 16:15:32 +01:00
|
|
|
world.setBlockState(pos, Blocks.NETHER_WART.getDefaultState(), 2);
|
|
|
|
farmer.extractEnergy(use);
|
2017-02-22 13:28:53 +01:00
|
|
|
return FarmerResult.SUCCESS;
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
2018-07-28 02:05:30 +02:00
|
|
|
return FarmerResult.FAIL;
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 13:28:53 +01:00
|
|
|
return FarmerResult.FAIL;
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-22 13:28:53 +01:00
|
|
|
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
2016-12-04 16:15:32 +01:00
|
|
|
int use = 500;
|
|
|
|
if(farmer.getEnergy() >= use){
|
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
if(state.getBlock() instanceof BlockNetherWart){
|
|
|
|
if(state.getValue(BlockNetherWart.AGE) >= 3){
|
2017-11-02 22:49:53 +01:00
|
|
|
NonNullList<ItemStack> drops = NonNullList.create();
|
|
|
|
state.getBlock().getDrops(drops, world, pos, state, 0);
|
|
|
|
if(!drops.isEmpty()){
|
2018-06-23 01:39:30 +02:00
|
|
|
boolean toInput = farmer.canAddToSeeds(drops);
|
|
|
|
if(toInput || farmer.canAddToOutput(drops)){
|
2016-12-04 16:15:32 +01:00
|
|
|
world.playEvent(2001, pos, Block.getStateId(state));
|
|
|
|
world.setBlockToAir(pos);
|
|
|
|
|
|
|
|
if(toInput){
|
2018-06-23 01:39:30 +02:00
|
|
|
farmer.addToSeeds(drops);
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
else{
|
2018-06-23 01:39:30 +02:00
|
|
|
farmer.addToOutput(drops);
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
farmer.extractEnergy(use);
|
2017-02-22 13:28:53 +01:00
|
|
|
return FarmerResult.SUCCESS;
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-28 02:05:30 +02:00
|
|
|
return FarmerResult.FAIL;
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-22 13:28:53 +01:00
|
|
|
return FarmerResult.FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority(){
|
2018-01-31 07:46:37 +01:00
|
|
|
return 3;
|
2016-12-04 16:15:32 +01:00
|
|
|
}
|
|
|
|
}
|