From cb52b290f66ef900aea213ef04c122bc05104f0b Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Thu, 19 Jun 2025 12:53:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(bukkit):=20=E4=BF=AE=E6=AD=A3=E5=8F=AF?= =?UTF-8?q?=E5=A0=86=E5=8F=A0=E6=96=B9=E5=9D=97=E8=A1=8C=E4=B8=BA=E4=B8=8D?= =?UTF-8?q?=E8=BF=98=E5=8E=9F=E5=8E=9F=E7=89=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../behavior/StackableBlockBehavior.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/StackableBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/StackableBlockBehavior.java index e4198b25f..a75504d60 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/StackableBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/StackableBlockBehavior.java @@ -8,6 +8,7 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState; import net.momirealms.craftengine.core.block.UpdateOption; import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory; import net.momirealms.craftengine.core.block.properties.IntegerProperty; +import net.momirealms.craftengine.core.entity.player.InteractionHand; import net.momirealms.craftengine.core.entity.player.InteractionResult; import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.item.Item; @@ -50,22 +51,36 @@ public class StackableBlockBehavior extends BukkitBlockBehavior { if (item == null) { return InteractionResult.PASS; } - if (this.items.contains(item.id()) && state.get(this.amountProperty) < this.amountProperty.max) { - ImmutableBlockState nextStage = state.cycle(this.amountProperty); - World world = context.getLevel(); - BlockPos pos = context.getClickedPos(); - Location location = new Location((org.bukkit.World) world.platformWorld(), pos.x(), pos.y(), pos.z()); - FastNMS.INSTANCE.method$LevelWriter$setBlock(world.serverWorld(), LocationUtils.toBlockPos(pos), nextStage.customBlockState().handle(), UpdateOption.UPDATE_NONE.flags()); - if (stackSound != null) { - location.getWorld().playSound(location, stackSound.id().toString(), SoundCategory.BLOCKS, stackSound.volume(), stackSound.pitch()); - } - FastNMS.INSTANCE.method$ItemStack$consume(item.getLiteralObject(), 1, player.serverPlayer()); - player.swingHand(context.getHand()); + if (!this.items.contains(item.id())) { + return InteractionResult.PASS; + } + BlockPos pos = context.getClickedPos(); + World world = context.getLevel(); + if (state.get(this.amountProperty) < this.amountProperty.max) { + updateStackableBlock(state, pos, world, item, player, context.getHand()); + return InteractionResult.SUCCESS_AND_CANCEL; + } + BlockPos actualPos = pos.relative(context.getClickedFace()); + ImmutableBlockState actualState = world.getBlockAt(actualPos).customBlockState(); + boolean isValid = actualState != null && !actualState.isEmpty() && actualState.contains(this.amountProperty); + if (isValid && actualState.get(this.amountProperty) < this.amountProperty.max) { + updateStackableBlock(actualState, actualPos, world, item, player, context.getHand()); return InteractionResult.SUCCESS_AND_CANCEL; } return InteractionResult.PASS; } + private void updateStackableBlock(ImmutableBlockState state, BlockPos pos, World world, Item item, Player player, InteractionHand hand) { + ImmutableBlockState nextStage = state.cycle(this.amountProperty); + Location location = new Location((org.bukkit.World) world.platformWorld(), pos.x(), pos.y(), pos.z()); + FastNMS.INSTANCE.method$LevelWriter$setBlock(world.serverWorld(), LocationUtils.toBlockPos(pos), nextStage.customBlockState().handle(), UpdateOption.UPDATE_NONE.flags()); + if (stackSound != null) { + location.getWorld().playSound(location, stackSound.id().toString(), SoundCategory.BLOCKS, stackSound.volume(), stackSound.pitch()); + } + FastNMS.INSTANCE.method$ItemStack$consume(item.getLiteralObject(), 1, player.serverPlayer()); + player.swingHand(hand); + } + public static class Factory implements BlockBehaviorFactory { @Override