9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-26 18:39:20 +00:00

fix(block): 修复只放了下半边的问题

This commit is contained in:
jhqwqmc
2025-06-19 11:08:22 +08:00
parent ef14147a0a
commit a71754c64a
5 changed files with 18 additions and 1 deletions

View File

@@ -111,6 +111,12 @@ public class DoorBlockBehavior extends BukkitBlockBehavior {
}
}
@Override
public void setPlacedBy(BlockPlaceContext context, ImmutableBlockState state) {
BlockPos pos = context.getClickedPos();
context.getLevel().setBlockAt(pos.x(), pos.y() + 1, pos.z(), state.with(this.halfProperty, DoubleBlockHalf.UPPER).customBlockState(), 3);
}
@Override
public ImmutableBlockState updateStateForPlacement(BlockPlaceContext context, ImmutableBlockState state) {
World world = context.getLevel();
@@ -191,7 +197,6 @@ public class DoorBlockBehavior extends BukkitBlockBehavior {
@Override
public InteractionResult useOnBlock(UseOnContext context, ImmutableBlockState state) {
if (!this.canOpenWithHand) {
if (!this.canOpenWithHand || context.getPlayer().isSecondaryUseActive()) {
return InteractionResult.PASS;
}

View File

@@ -159,6 +159,8 @@ public class BlockItemBehavior extends ItemBehavior {
item.load();
}
block.setPlacedBy(context, blockStateToPlace);
player.swingHand(context.getHand());
context.getLevel().playBlockSound(position, blockStateToPlace.sounds().placeSound());
world.sendGameEvent(bukkitPlayer, GameEvent.BLOCK_PLACE, new Vector(pos.x(), pos.y(), pos.z()));

View File

@@ -194,4 +194,9 @@ public abstract class AbstractCustomBlock implements CustomBlock {
}
return state;
}
@Override
public void setPlacedBy(BlockPlaceContext context, ImmutableBlockState state) {
this.behavior.setPlacedBy(context, state);
}
}

View File

@@ -95,6 +95,9 @@ public abstract class BlockBehavior {
return state;
}
public void setPlacedBy(BlockPlaceContext context, ImmutableBlockState state) {
}
public InteractionResult useOnBlock(UseOnContext context, ImmutableBlockState state) {
return InteractionResult.PASS;
}

View File

@@ -37,6 +37,8 @@ public interface CustomBlock {
ImmutableBlockState getStateForPlacement(BlockPlaceContext context);
void setPlacedBy(BlockPlaceContext context, ImmutableBlockState state);
interface Builder {
Builder events(Map<EventTrigger, List<Function<PlayerOptionalContext>>> events);