[Change] FeatureSaplingBlocks will grow at onece in creative
This commit is contained in:
parent
ba09219fed
commit
f0dd0e698d
2 changed files with 21 additions and 15 deletions
|
@ -112,7 +112,7 @@ public class BonemealAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public boolean runSpreaders(ItemStack itemStack, Level level, BlockPos blockPos) {
|
public boolean runSpreaders(ItemStack itemStack, Level level, BlockPos blockPos, boolean forceBonemeal) {
|
||||||
BlockState blockState = level.getBlockState(blockPos);
|
BlockState blockState = level.getBlockState(blockPos);
|
||||||
BonemealBlockSpreader spreader = org.betterx.bclib.api.v3.bonemeal.BonemealAPI
|
BonemealBlockSpreader spreader = org.betterx.bclib.api.v3.bonemeal.BonemealAPI
|
||||||
.INSTANCE
|
.INSTANCE
|
||||||
|
@ -136,7 +136,7 @@ public class BonemealAPI {
|
||||||
if (fSpreader != null) {
|
if (fSpreader != null) {
|
||||||
if (fSpreader.isValidBonemealTarget(level, blockPos, blockState, level.isClientSide)) {
|
if (fSpreader.isValidBonemealTarget(level, blockPos, blockState, level.isClientSide)) {
|
||||||
if (level instanceof ServerLevel) {
|
if (level instanceof ServerLevel) {
|
||||||
if (fSpreader.isBonemealSuccess(level, level.random, blockPos, blockState)) {
|
if (forceBonemeal || fSpreader.isBonemealSuccess(level, level.random, blockPos, blockState)) {
|
||||||
fSpreader.performBonemeal((ServerLevel) level, level.random, blockPos, blockState);
|
fSpreader.performBonemeal((ServerLevel) level, level.random, blockPos, blockState);
|
||||||
}
|
}
|
||||||
itemStack.shrink(1);
|
itemStack.shrink(1);
|
||||||
|
|
|
@ -1,34 +1,43 @@
|
||||||
package org.betterx.bclib.mixin.common;
|
package org.betterx.bclib.mixin.common;
|
||||||
|
|
||||||
|
import org.betterx.bclib.api.v3.bonemeal.BonemealAPI;
|
||||||
|
import org.betterx.bclib.blocks.FeatureSaplingBlock;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.item.BoneMealItem;
|
import net.minecraft.world.item.BoneMealItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.BonemealableBlock;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(BoneMealItem.class)
|
@Mixin(BoneMealItem.class)
|
||||||
public class BoneMealItemMixin {
|
public class BoneMealItemMixin {
|
||||||
@Unique
|
|
||||||
private static final MutableBlockPos BCLIB_BLOCK_POS = new MutableBlockPos();
|
|
||||||
|
|
||||||
@Inject(method = "useOn", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "useOn", at = @At("HEAD"), cancellable = true)
|
||||||
private void bclib_onUse(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {
|
private void bclib_onUse(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {
|
||||||
Level world = context.getLevel();
|
Level level = context.getLevel();
|
||||||
final BlockPos blockPos = context.getClickedPos();
|
final BlockPos blockPos = context.getClickedPos();
|
||||||
if (!world.isClientSide()) {
|
|
||||||
|
|
||||||
if (!context.getPlayer().isCreative()) {
|
if (context.getPlayer().isCreative()) {
|
||||||
context.getItemInHand().shrink(1);
|
if (BonemealAPI.INSTANCE.runSpreaders(context.getItemInHand(), level, blockPos, true)) {
|
||||||
|
info.setReturnValue(InteractionResult.sidedSuccess(level.isClientSide));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final BlockState blockState = level.getBlockState(blockPos);
|
||||||
|
if (blockState.getBlock() instanceof BonemealableBlock bblock
|
||||||
|
&& level instanceof ServerLevel server
|
||||||
|
&& blockState.getBlock() instanceof FeatureSaplingBlock<?, ?>
|
||||||
|
) {
|
||||||
|
bblock.performBonemeal(server, context.getLevel().getRandom(), blockPos, blockState);
|
||||||
|
info.setReturnValue(InteractionResult.sidedSuccess(level.isClientSide));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,10 +48,7 @@ public class BoneMealItemMixin {
|
||||||
BlockPos blockPos,
|
BlockPos blockPos,
|
||||||
CallbackInfoReturnable<Boolean> cir
|
CallbackInfoReturnable<Boolean> cir
|
||||||
) {
|
) {
|
||||||
if (org.betterx.bclib.api.v3.bonemeal.BonemealAPI
|
if (BonemealAPI.INSTANCE.runSpreaders(itemStack, level, blockPos, false)) {
|
||||||
.INSTANCE
|
|
||||||
.runSpreaders(itemStack, level, blockPos)
|
|
||||||
) {
|
|
||||||
cir.setReturnValue(true);
|
cir.setReturnValue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue