Skip to content

Commit

Permalink
Fix (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Sep 15, 2024
1 parent 786ff6f commit 105ad7d
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
Expand Down Expand Up @@ -136,16 +135,25 @@ protected static void updateCrop(ServerLevel level, IntegerProperty age, Block c
BlockState cropState = level.getBlockState(basePos);
int i = player.getInventory().findSlotMatchingItem(crop.getCloneItemStack(level, basePos, cropState));
if (dropsFlags.getLeft()) {
// If seeds are dropped, simply revert the crop's age.
level.setBlockAndUpdate(basePos, level.getBlockState(basePos).setValue(age, 0));
} else if (ModConfig.getUseSeedsFromInventory() && i >= 0) {
// If the seeds were not dropped, but are in the inventory and the mod is allowed to use them, then revert the crop's age and consume the seeds from the inventory.
level.setBlockAndUpdate(basePos, level.getBlockState(basePos).setValue(age, 0));
if (!player.isCreative()) {
player.getInventory().getItem(i).shrink(1);
}
} else {
level.setBlockAndUpdate(basePos, Blocks.AIR.defaultBlockState());
if (isTallButSeparate(crop)) {
// If the crop is tall but separate, revert its age without destroying it.
level.setBlockAndUpdate(basePos, level.getBlockState(basePos).setValue(age, 0));
} else {
// If the crop is not tall but separate (it's single or tall and not separate), destroy it and prevent drops since they will be accounted for in the condition below.
level.destroyBlock(basePos, false, player);
}
}
if (level.getBlockState(basePos).is(BlockTags.CROPS) && level.getBlockState(basePos.above()).is(crop) && isNotTallButSeparate(crop)) {
if (level.getBlockState(basePos).is(BlockTags.CROPS) && level.getBlockState(basePos.above()).is(crop) && !isTallButSeparate(crop)) {
// If the crop is tall and not separate, destroy it and drop only if custom drops were not set.
level.destroyBlock(basePos.above(), !dropsFlags.getRight(), player);
}
}
Expand All @@ -160,7 +168,7 @@ protected static void updateCrop(ServerLevel level, IntegerProperty age, Block c
*/
protected static BlockPos getBasePos(ServerLevel level, Block crop, BlockPos pos) {
BlockPos basePos = pos;
while (level.getBlockState(pos).is(BlockTags.CROPS) && isNotTallButSeparate(crop) && level.getBlockState(basePos.below()).is(crop)) {
while (level.getBlockState(pos).is(BlockTags.CROPS) && !isTallButSeparate(crop) && level.getBlockState(basePos.below()).is(crop)) {
basePos = basePos.below();
}
return basePos;
Expand Down Expand Up @@ -279,8 +287,8 @@ protected static boolean canHarvest(Level level, BlockState crop, BlockPos pos,
* @param crop crop.
* @return whether the crop is tall, but should be considered as a single one.
*/
protected static boolean isNotTallButSeparate(Block crop) {
return !"farmersdelight:tomatoes".equalsIgnoreCase(BlockUtils.getStringKey(crop));
protected static boolean isTallButSeparate(Block crop) {
return "farmersdelight:tomatoes".equalsIgnoreCase(BlockUtils.getStringKey(crop));
}

/**
Expand Down

0 comments on commit 105ad7d

Please sign in to comment.