mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
修正交互
This commit is contained in:
@@ -108,7 +108,10 @@ public class AxeItemBehavior extends ItemBehavior {
|
||||
if (!InteractUtils.isInteractable(
|
||||
bukkitPlayer, BlockStateUtils.fromBlockData(customState.vanillaBlockState().literalObject()),
|
||||
context.getHitResult(), item
|
||||
) || player.isSecondaryUseActive()) {
|
||||
) || (player.isSecondaryUseActive() && !InteractUtils.isIgnoreSneaking(
|
||||
bukkitPlayer, BlockStateUtils.fromBlockData(customState.vanillaBlockState().literalObject()),
|
||||
context.getHitResult(), item
|
||||
))) {
|
||||
player.swingHand(context.getHand());
|
||||
}
|
||||
// shrink item amount
|
||||
|
||||
@@ -88,8 +88,9 @@ public class FlintAndSteelItemBehavior extends ItemBehavior {
|
||||
context.getHitResult(), (Item<ItemStack>) context.getItem())) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
// 且没有shift
|
||||
if (!player.isSecondaryUseActive()) {
|
||||
// 且没有shift或者忽略潜行的可交互方块
|
||||
if (!player.isSecondaryUseActive() || InteractUtils.isIgnoreSneaking((Player) player.platformPlayer(), vanillaBlockState,
|
||||
context.getHitResult(), (Item<ItemStack>) context.getItem())) {
|
||||
player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f));
|
||||
}
|
||||
} else {
|
||||
@@ -110,7 +111,7 @@ public class FlintAndSteelItemBehavior extends ItemBehavior {
|
||||
// 客户端觉得这玩意可交互,就会忽略声音
|
||||
if (InteractUtils.isInteractable((Player) player.platformPlayer(), vanillaBlockState, context.getHitResult(), (Item<ItemStack>) context.getItem())) {
|
||||
// 如果按住了shift,则代表尝试对侧面方块点火
|
||||
if (player.isSecondaryUseActive()) {
|
||||
if (player.isSecondaryUseActive() && !InteractUtils.isIgnoreSneaking((Player) player.platformPlayer(), vanillaBlockState, context.getHitResult(), (Item<ItemStack>) context.getItem())) {
|
||||
// 如果底部不能燃烧,则燃烧点位为侧面,需要补发
|
||||
if (!belowCanBurn) {
|
||||
player.playSound(FLINT_SOUND, firePos, SoundSource.BLOCK, 1f, RandomUtils.generateRandomFloat(0.8f, 1.2f));
|
||||
|
||||
@@ -257,7 +257,7 @@ public class ItemEventListener implements Listener {
|
||||
// so we should check and resend sounds on BlockPlaceEvent
|
||||
BlockData craftBlockData = BlockStateUtils.fromBlockData(immutableBlockState.vanillaBlockState().literalObject());
|
||||
if (InteractUtils.isInteractable(player, craftBlockData, hitResult, itemInHand)) {
|
||||
if (!serverPlayer.isSecondaryUseActive()) {
|
||||
if (!serverPlayer.isSecondaryUseActive() || InteractUtils.isIgnoreSneaking(player, craftBlockData, hitResult, itemInHand)) {
|
||||
serverPlayer.setResendSound();
|
||||
}
|
||||
} else {
|
||||
@@ -276,7 +276,7 @@ public class ItemEventListener implements Listener {
|
||||
return;
|
||||
} else {
|
||||
// todo 实际上这里的处理并不正确,因为判断玩家是否能够放置那个方块需要更加细节的判断。比如玩家无法对着树叶放置火把,但是交互事件依然触发,此情况下不可丢弃自定义行为。
|
||||
if (serverPlayer.isSecondaryUseActive() || !InteractUtils.isInteractable(player, blockData, hitResult, itemInHand)) {
|
||||
if ((serverPlayer.isSecondaryUseActive() && InteractUtils.isIgnoreSneaking(player, blockData, hitResult, itemInHand)) || !InteractUtils.isInteractable(player, blockData, hitResult, itemInHand)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -290,9 +290,10 @@ public class ItemEventListener implements Listener {
|
||||
if (optionalItemBehaviors.isPresent()) {
|
||||
// 检测是否可交互应当只判断原版方块,因为自定义方块早就判断过了,如果可交互不可能到这一步
|
||||
boolean interactable = immutableBlockState == null && InteractUtils.isInteractable(player, blockData, hitResult, itemInHand);
|
||||
boolean isIgnoreSneaking = InteractUtils.isIgnoreSneaking(player, blockData, hitResult, itemInHand);
|
||||
// 如果方块可交互但是玩家没shift,那么原版的方块交互优先,取消自定义物品的behavior
|
||||
// todo 如果我的物品行为允许某些交互呢?是否值得进一步处理?
|
||||
if (!serverPlayer.isSecondaryUseActive() && interactable) {
|
||||
if ((!serverPlayer.isSecondaryUseActive() || isIgnoreSneaking) && interactable) {
|
||||
return;
|
||||
}
|
||||
UseOnContext useOnContext = new UseOnContext(serverPlayer, hand, itemInHand, hitResult);
|
||||
@@ -315,7 +316,7 @@ public class ItemEventListener implements Listener {
|
||||
// 执行物品右键事件
|
||||
if (hasCustomItem) {
|
||||
// 要求服务端侧这个方块不可交互,或玩家处于潜行状态
|
||||
if (serverPlayer.isSecondaryUseActive() || !InteractUtils.isInteractable(player, blockData, hitResult, itemInHand)) {
|
||||
if ((serverPlayer.isSecondaryUseActive() && !InteractUtils.isIgnoreSneaking(player, blockData, hitResult, itemInHand)) || !InteractUtils.isInteractable(player, blockData, hitResult, itemInHand)) {
|
||||
Cancellable dummy = Cancellable.dummy();
|
||||
PlayerOptionalContext context = PlayerOptionalContext.of(serverPlayer, ContextHolder.builder()
|
||||
.withParameter(DirectContextParameters.BLOCK, new BukkitExistingBlock(block))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user