From 037162ba9108bb0cdfd9ee39e619deecc658c567 Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Fri, 28 Jun 2024 18:54:40 +0800 Subject: [PATCH] fix: fix block interacting and spawn egg --- .../component/player/EntityPlayerBaseComponent.java | 4 ++-- .../api/item/component/common/ItemBaseComponent.java | 9 +++++++++ .../component/player/EntityPlayerBaseComponentImpl.java | 2 +- .../processor/InventoryTransactionPacketProcessor.java | 9 +++++++-- .../network/processor/PlayerActionPacketProcessor.java | 8 ++++---- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Allay-API/src/main/java/org/allaymc/api/entity/component/player/EntityPlayerBaseComponent.java b/Allay-API/src/main/java/org/allaymc/api/entity/component/player/EntityPlayerBaseComponent.java index 48aa20600..c9b8a29a6 100644 --- a/Allay-API/src/main/java/org/allaymc/api/entity/component/player/EntityPlayerBaseComponent.java +++ b/Allay-API/src/main/java/org/allaymc/api/entity/component/player/EntityPlayerBaseComponent.java @@ -42,9 +42,9 @@ public interface EntityPlayerBaseComponent extends EntityBaseComponent, ChunkLoa void setCrawling(boolean crawling); - boolean isInteractingBlock(); + boolean isUsingItem(); - void setInteractingBlock(boolean interactingBlock); + void setUsingItem(boolean usingItemOnBlock); int getHandSlot(); diff --git a/Allay-API/src/main/java/org/allaymc/api/item/component/common/ItemBaseComponent.java b/Allay-API/src/main/java/org/allaymc/api/item/component/common/ItemBaseComponent.java index 9f5cbb445..9cf738aea 100644 --- a/Allay-API/src/main/java/org/allaymc/api/item/component/common/ItemBaseComponent.java +++ b/Allay-API/src/main/java/org/allaymc/api/item/component/common/ItemBaseComponent.java @@ -91,9 +91,18 @@ default void clearStackNetworkId() { void loadExtraTag(NbtMap extraTag); + /** + * Called when player right-click a block no matter the return value of player.isUsingItem() + * @param dimension The dimension the player is in + * @param placeBlockPos The position of the block being right-clicked + * @param interactInfo Information about the interaction + */ + default void rightClickItemOn(Dimension dimension, Vector3ic placeBlockPos, PlayerInteractInfo interactInfo) {} + /** * Attempt to use this item on a block. *
+ * This method will be called only when client think "he can" use the item. In other words, when player.isUsingItem() return true. * This method should handle reducing item count, durability, etc., on successful use. * No need to send item updates separately as the caller will handle it. *
diff --git a/Allay-Server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java b/Allay-Server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java
index d2d0fd3a1..7f7f4db3d 100644
--- a/Allay-Server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java
+++ b/Allay-Server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java
@@ -100,7 +100,7 @@ public class EntityPlayerBaseComponentImpl extends EntityBaseComponentImpl