Fix up Nether Wart farmer behavior

This commit is contained in:
Mrbysco 2024-10-17 18:53:49 +02:00
parent d8ad92c447
commit 124cac11e4

View file

@ -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,15 +37,15 @@ 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();
if (result.isTrue() || wartState.canSurvive(world, pos)) {
world.setBlock(pos, wartState, 2);
farmer.extractEnergy(use); farmer.extractEnergy(use);
return FarmerResult.SUCCESS; return FarmerResult.SUCCESS;
} }
return FarmerResult.FAIL;
}
} }
return FarmerResult.FAIL; return FarmerResult.FAIL;
} }
@ -53,8 +55,7 @@ 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));
@ -75,8 +76,6 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior {
} }
} }
} }
return FarmerResult.FAIL;
}
} }
return FarmerResult.FAIL; return FarmerResult.FAIL;
} }