2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.common.misc.apiimpl.farmer;
|
2017-01-31 18:49:42 +01:00
|
|
|
|
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;
|
2017-09-17 08:47:04 +02:00
|
|
|
import net.minecraft.util.NonNullList;
|
2017-01-31 18:49:42 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2018-07-28 02:05:30 +02:00
|
|
|
public class ReedFarmerBehavior implements IFarmerBehavior {
|
2017-01-31 18:49:42 +01:00
|
|
|
|
|
|
|
@Override
|
2018-07-28 02:05:30 +02:00
|
|
|
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer) {
|
2017-01-31 18:49:42 +01:00
|
|
|
int use = 250;
|
2018-07-28 02:05:30 +02:00
|
|
|
if (farmer.getEnergy() >= use) {
|
|
|
|
if (seed.getItem() == Items.REEDS) {
|
|
|
|
if (Blocks.REEDS.canPlaceBlockAt(world, pos)) {
|
2017-01-31 18:49:42 +01:00
|
|
|
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
|
2018-07-28 02:05:30 +02:00
|
|
|
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer) {
|
2017-01-31 18:49:42 +01:00
|
|
|
int use = 250;
|
2018-07-28 02:05:30 +02:00
|
|
|
if (farmer.getEnergy() >= use) {
|
2017-01-31 18:49:42 +01:00
|
|
|
IBlockState state = world.getBlockState(pos);
|
2018-07-28 02:05:30 +02:00
|
|
|
if (state.getBlock() instanceof BlockReed) {
|
2017-02-22 13:28:53 +01:00
|
|
|
FarmerResult result = FarmerResult.STOP_PROCESSING;
|
|
|
|
|
2018-07-28 02:05:30 +02:00
|
|
|
for (int i = 2; i >= 1; --i) {
|
|
|
|
if (farmer.getEnergy() >= use) {
|
2017-01-31 18:49:42 +01:00
|
|
|
BlockPos up = pos.up(i);
|
|
|
|
IBlockState upState = world.getBlockState(up);
|
2018-07-28 02:05:30 +02:00
|
|
|
if (upState.getBlock() instanceof BlockReed) {
|
|
|
|
NonNullList<ItemStack> drops = NonNullList.create();
|
2017-09-17 08:47:04 +02:00
|
|
|
upState.getBlock().getDrops(drops, world, pos, state, 0);
|
2017-01-31 18:49:42 +01:00
|
|
|
|
2018-07-28 02:05:30 +02:00
|
|
|
if (!drops.isEmpty()) {
|
|
|
|
if (farmer.canAddToOutput(drops)) {
|
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);
|
2018-06-23 01:39:30 +02:00
|
|
|
farmer.addToOutput(drops);
|
2017-02-22 13:28:53 +01:00
|
|
|
|
2018-07-28 02:05:30 +02:00
|
|
|
result = FarmerResult.STOP_PROCESSING;
|
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
|
2018-07-28 02:05:30 +02:00
|
|
|
public int getPriority() {
|
2018-01-31 07:46:37 +01:00
|
|
|
return 2;
|
2017-01-31 18:49:42 +01:00
|
|
|
}
|
|
|
|
}
|