2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.common.misc.apiimpl.farmer;
|
2017-02-22 13:28:53 +01:00
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
|
|
|
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
|
|
|
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
2020-09-09 16:49:01 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
2017-02-22 13:28:53 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2017-09-17 08:47:04 +02:00
|
|
|
import net.minecraft.util.NonNullList;
|
2017-02-22 13:28:53 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2018-07-28 02:05:30 +02:00
|
|
|
public class MelonPumpkinFarmerBehavior implements IFarmerBehavior {
|
2017-02-22 13:28:53 +01:00
|
|
|
|
|
|
|
@Override
|
2018-07-28 02:05:30 +02:00
|
|
|
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer) {
|
2017-02-22 13:28:53 +01:00
|
|
|
int use = 350;
|
2018-07-28 02:05:30 +02:00
|
|
|
if (farmer.getEnergy() >= use * 2) {
|
|
|
|
if (StackUtil.isValid(seed)) {
|
2017-02-22 13:28:53 +01:00
|
|
|
Item seedItem = seed.getItem();
|
|
|
|
boolean isPumpkin = seedItem == Items.PUMPKIN_SEEDS;
|
2018-07-28 02:05:30 +02:00
|
|
|
if (isPumpkin || seedItem == Items.MELON_SEEDS) {
|
2019-02-27 19:53:05 +01:00
|
|
|
if (pos.getX() % 2 == 0 == (pos.getZ() % 2 == 0)) {
|
2017-02-22 13:28:53 +01:00
|
|
|
IBlockState toPlant = (isPumpkin ? Blocks.PUMPKIN_STEM : Blocks.MELON_STEM).getDefaultState();
|
2018-07-28 02:05:30 +02:00
|
|
|
if (DefaultFarmerBehavior.defaultPlant(world, pos, toPlant, farmer, use)) return FarmerResult.SUCCESS;
|
2017-02-22 13:28:53 +01:00
|
|
|
}
|
|
|
|
return FarmerResult.STOP_PROCESSING;
|
|
|
|
}
|
2018-07-28 02:05:30 +02:00
|
|
|
return FarmerResult.FAIL;
|
2017-02-22 13:28:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FarmerResult.FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-28 02:05:30 +02:00
|
|
|
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer) {
|
2017-02-22 13:28:53 +01:00
|
|
|
int use = 500;
|
2018-07-28 02:05:30 +02:00
|
|
|
if (farmer.getEnergy() >= use) {
|
2017-02-22 13:28:53 +01:00
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
Block block = state.getBlock();
|
2018-07-28 02:05:30 +02:00
|
|
|
if (block == Blocks.PUMPKIN || block == Blocks.MELON_BLOCK) {
|
|
|
|
NonNullList<ItemStack> drops = NonNullList.create();
|
2017-09-17 08:47:04 +02:00
|
|
|
block.getDrops(drops, world, pos, state, 0);
|
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, pos, Block.getStateId(state));
|
|
|
|
world.setBlockToAir(pos);
|
|
|
|
|
|
|
|
farmer.extractEnergy(use);
|
2018-06-23 01:39:30 +02:00
|
|
|
farmer.addToOutput(drops);
|
2017-02-22 13:28:53 +01:00
|
|
|
|
|
|
|
return FarmerResult.SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FarmerResult.STOP_PROCESSING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FarmerResult.FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-28 02:05:30 +02:00
|
|
|
public int getPriority() {
|
2017-02-22 13:28:53 +01:00
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
}
|