Skip to content

Commit

Permalink
Clicking on Fruit Leaves with Fruit Item in creative will now place t…
Browse files Browse the repository at this point in the history
…he fruit block below the leaves (Assuming there is air below)

Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Nov 17, 2024
1 parent 6cb7317 commit 5352eb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Add Protea to Fragment Jungle
- Hitting Fruit Blocks with a Projectile will now cause the block to break with the fruit dropping if it is fully grown
- Fix Incompatibily with Organics Mod
- Clicking on Fruit Leaves with Fruit Item in creative will now place the fruit block below the leaves (Assuming there is air below)

# 2.2.3
- Add Apple Fruit Decorator to Orchard Trees
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.potionstudios.biomeswevegone.world.level.block.plants.tree.fruit.BWGFruitBlock;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -44,6 +49,16 @@ private void placeFruit(@NotNull Level level, @NotNull BlockPos pos) {
level.setBlock(pos, fruitBlock.get().defaultBlockState().setValue(BWGFruitBlock.AGE, 0), 2);
}

@Override
protected @NotNull ItemInteractionResult useItemOn(@NotNull ItemStack stack, @NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand hand, @NotNull BlockHitResult hitResult) {
if (player.isCreative() && !level.isClientSide())
if (stack.getItem().getDefaultInstance().is(fruitBlock.get().getFruit()) && level.getBlockState(pos.below()).isAir()) {
placeFruit(level, pos.below());
return ItemInteractionResult.SUCCESS;
}
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
}

@Override
public boolean isValidBonemealTarget(@NotNull LevelReader level, @NotNull BlockPos pos, BlockState state) {
return !state.getValue(PERSISTENT) && level.getBlockState(pos.below()).isAir();
Expand Down

0 comments on commit 5352eb4

Please sign in to comment.