mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-10-30 06:10:51 +01:00
Fix up Nether Wart farmer behavior
This commit is contained in:
parent
d8ad92c447
commit
124cac11e4
1 changed files with 24 additions and 25 deletions
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
||||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
@ -27,6 +28,7 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.storage.loot.LootParams;
|
import net.minecraft.world.level.storage.loot.LootParams;
|
||||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.neoforged.neoforge.common.util.TriState;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -35,14 +37,14 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior {
|
||||||
@Override
|
@Override
|
||||||
public FarmerResult tryPlantSeed(ItemStack seed, Level world, BlockPos pos, IFarmer farmer) {
|
public FarmerResult tryPlantSeed(ItemStack seed, Level world, BlockPos pos, IFarmer farmer) {
|
||||||
int use = 500;
|
int use = 500;
|
||||||
if (farmer.getEnergy() >= use) {
|
if (farmer.getEnergy() >= use && seed.is(Items.NETHER_WART)) {
|
||||||
if (seed.getItem() == Items.NETHER_WART) {
|
BlockState belowState = world.getBlockState(pos.below());
|
||||||
if (world.getBlockState(pos.below()).getBlock().canSustainPlant(world.getBlockState(pos), world, pos.below(), Direction.UP, Blocks.NETHER_WART.defaultBlockState()).isTrue()) {
|
TriState result = belowState.canSustainPlant(world, pos, Direction.UP, Blocks.NETHER_WART.defaultBlockState());
|
||||||
world.setBlock(pos, Blocks.NETHER_WART.defaultBlockState(), 2);
|
BlockState wartState = Blocks.NETHER_WART.defaultBlockState();
|
||||||
farmer.extractEnergy(use);
|
if (result.isTrue() || wartState.canSurvive(world, pos)) {
|
||||||
return FarmerResult.SUCCESS;
|
world.setBlock(pos, wartState, 2);
|
||||||
}
|
farmer.extractEnergy(use);
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
|
@ -53,29 +55,26 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior {
|
||||||
int use = 500;
|
int use = 500;
|
||||||
if (farmer.getEnergy() >= use) {
|
if (farmer.getEnergy() >= use) {
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
if (state.getBlock() instanceof NetherWartBlock) {
|
if (state.getBlock() instanceof NetherWartBlock && state.getValue(BlockStateProperties.AGE_3) >= 3) {
|
||||||
if (state.getValue(BlockStateProperties.AGE_3) >= 3) {
|
List<ItemStack> drops = state.getDrops(new LootParams.Builder(world)
|
||||||
List<ItemStack> drops = state.getDrops(new LootParams.Builder(world)
|
|
||||||
.withParameter(LootContextParams.ORIGIN, new Vec3(pos.getX(), pos.getY(), pos.getZ()))
|
.withParameter(LootContextParams.ORIGIN, new Vec3(pos.getX(), pos.getY(), pos.getZ()))
|
||||||
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY));
|
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY));
|
||||||
if (!drops.isEmpty()) {
|
if (!drops.isEmpty()) {
|
||||||
boolean toInput = farmer.canAddToSeeds(drops);
|
boolean toInput = farmer.canAddToSeeds(drops);
|
||||||
if (toInput || farmer.canAddToOutput(drops)) {
|
if (toInput || farmer.canAddToOutput(drops)) {
|
||||||
world.levelEvent(2001, pos, Block.getId(state));
|
world.levelEvent(2001, pos, Block.getId(state));
|
||||||
world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
||||||
|
|
||||||
if (toInput) {
|
if (toInput) {
|
||||||
farmer.addToSeeds(drops);
|
farmer.addToSeeds(drops);
|
||||||
} else {
|
} else {
|
||||||
farmer.addToOutput(drops);
|
farmer.addToOutput(drops);
|
||||||
}
|
|
||||||
|
|
||||||
farmer.extractEnergy(use);
|
|
||||||
return FarmerResult.SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
farmer.extractEnergy(use);
|
||||||
|
return FarmerResult.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
|
|
Loading…
Reference in a new issue