From fb4ae9357bc4a6d7ef68536d08559be3559d8921 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Wed, 3 Dec 2025 17:19:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BA=A7=E6=A4=85=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E4=B8=8E=E4=B9=90=E9=AD=82=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hitbox/HappyGhastFurnitureHitbox.java | 44 ++++++++++--------- .../HappyGhastFurnitureHitboxConfig.java | 2 +- .../hitbox/InteractionFurnitureHitbox.java | 2 +- .../InteractionFurnitureHitboxConfig.java | 6 +-- .../hitbox/ShulkerFurnitureHitbox.java | 2 +- .../hitbox/ShulkerFurnitureHitboxConfig.java | 25 ++++++----- .../plugin/network/BukkitNetworkManager.java | 3 ++ .../configuration/furniture/wooden_chair.yml | 1 + .../furniture/hitbox/FurnitureHitboxPart.java | 2 +- 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java index 8905b7c2f..fcf530b95 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitbox.java @@ -11,12 +11,9 @@ import net.momirealms.craftengine.core.entity.furniture.Furniture; import net.momirealms.craftengine.core.entity.furniture.hitbox.FurnitureHitboxPart; import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.plugin.CraftEngine; -import net.momirealms.craftengine.core.util.QuaternionUtils; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.WorldPosition; import net.momirealms.craftengine.core.world.collision.AABB; -import org.joml.Quaternionf; -import org.joml.Vector3f; import java.util.ArrayList; import java.util.Collections; @@ -27,38 +24,37 @@ import java.util.function.Consumer; public class HappyGhastFurnitureHitbox extends AbstractFurnitureHitBox { private final HappyGhastFurnitureHitboxConfig config; private final Collider collider; - private final Object spawnPacket; private final Object despawnPacket; private final FurnitureHitboxPart part; + private final Vec3d pos; + private final List packets; + private final int entityId; + private final float yaw; public HappyGhastFurnitureHitbox(Furniture furniture, HappyGhastFurnitureHitboxConfig config) { super(furniture, config); this.config = config; WorldPosition position = furniture.position(); - Quaternionf conjugated = QuaternionUtils.toQuaternionf(0f, (float) Math.toRadians(180 - position.yRot()), 0f).conjugate(); - Vector3f offset = conjugated.transform(new Vector3f(config.position())); - Vec3d pos = Furniture.getRelativePosition(position, config.position()); - AABB aabb = AABB.fromInteraction(pos, 3 * config.scale(), 3 * config.scale()); - int happyGhastId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet(); - List packets = new ArrayList<>(3); - packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( - happyGhastId, UUID.randomUUID(), position.x + offset.x, position.y + offset.y, position.z + offset.z, 0, position.yRot, - MEntityTypes.HAPPY_GHAST, 0, CoreReflections.instance$Vec3$Zero, 0 - )); - packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(happyGhastId, config.cachedValues())); + this.pos = Furniture.getRelativePosition(position, config.position()); + double bbSize = 4 * config.scale(); + AABB aabb = AABB.fromInteraction(this.pos, bbSize, bbSize); + this.yaw = position.yRot; + this.entityId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet(); + this.packets = new ArrayList<>(3); + this.packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(this.entityId, config.cachedValues())); if (config.scale() != 1) { try { Object attributeInstance = CoreReflections.constructor$AttributeInstance.newInstance(MAttributeHolders.SCALE, (Consumer) (o) -> {}); CoreReflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, config.scale()); - packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(happyGhastId, Collections.singletonList(attributeInstance))); + this.packets.add(NetworkReflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(this.entityId, Collections.singletonList(attributeInstance))); } catch (ReflectiveOperationException e) { CraftEngine.instance().logger().warn("Failed to apply scale attribute", e); } } - this.collider = createCollider(furniture.world(), pos, aabb, config.hardCollision(), config.blocksBuilding(), config.canBeHitByProjectile()); - this.part = new FurnitureHitboxPart(happyGhastId, aabb, pos); - this.spawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets); - this.despawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(new IntArrayList() {{ add(happyGhastId); }}); + this.packets.add(FastNMS.INSTANCE.constructor$ClientboundEntityPositionSyncPacket(this.entityId, this.pos.x, this.pos.y, this.pos.z, 0, position.yRot, false)); + this.collider = createCollider(furniture.world(), this.pos, aabb, config.hardCollision(), config.blocksBuilding(), config.canBeHitByProjectile()); + this.part = new FurnitureHitboxPart(this.entityId, aabb, this.pos, false); + this.despawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(new IntArrayList() {{ add(entityId); }}); } @Override @@ -73,7 +69,13 @@ public class HappyGhastFurnitureHitbox extends AbstractFurnitureHitBox { @Override public void show(Player player) { - player.sendPacket(this.spawnPacket, false); + List packets = new ArrayList<>(); + packets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( + this.entityId, UUID.randomUUID(), this.pos.x, player.y() - (this.config.scale() * 4 + 16), this.pos.z, 0, this.yaw, + MEntityTypes.HAPPY_GHAST, 0, CoreReflections.instance$Vec3$Zero, 0 + )); + packets.addAll(this.packets); + player.sendPacket(FastNMS.INSTANCE.constructor$ClientboundBundlePacket(packets), false); } @Override diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitboxConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitboxConfig.java index 7e28b68da..1d2cffb8a 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitboxConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/HappyGhastFurnitureHitboxConfig.java @@ -59,7 +59,7 @@ public class HappyGhastFurnitureHitboxConfig extends AbstractFurnitureHitBoxConf public void prepareForPlacement(WorldPosition targetPos, Consumer aabbConsumer) { if (this.blocksBuilding) { Vec3d relativePosition = Furniture.getRelativePosition(targetPos, this.position); - aabbConsumer.accept(AABB.fromInteraction(relativePosition, 3 * this.scale, 3 * this.scale)); + aabbConsumer.accept(AABB.fromInteraction(relativePosition, 4 * this.scale, 4 * this.scale)); } } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitbox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitbox.java index 44380525c..c44037500 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitbox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitbox.java @@ -37,7 +37,7 @@ public class InteractionFurnitureHitbox extends AbstractFurnitureHitBox { ), FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(interactionId, config.cachedValues()) )); - this.part = new FurnitureHitboxPart(interactionId, aabb, pos); + this.part = new FurnitureHitboxPart(interactionId, aabb, pos, config.responsive()); this.despawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(new IntArrayList() {{ add(interactionId); }}); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitboxConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitboxConfig.java index a3e853d17..68be109f9 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitboxConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/InteractionFurnitureHitboxConfig.java @@ -33,14 +33,14 @@ public class InteractionFurnitureHitboxConfig extends AbstractFurnitureHitBoxCon boolean canBeHitByProjectile, boolean invisible, Vector3f size, - boolean responsive) { + boolean interactive) { super(seats, position, canUseItemOn, blocksBuilding, canBeHitByProjectile); this.size = size; - this.responsive = responsive; + this.responsive = interactive; this.invisible = invisible; InteractionEntityData.Height.addEntityDataIfNotDefaultValue(size.y, cachedValues); InteractionEntityData.Width.addEntityDataIfNotDefaultValue(size.x, cachedValues); - InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(responsive, cachedValues); + InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(interactive, cachedValues); if (invisible) { BaseEntityData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, cachedValues); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java index 9a6c39d43..e4ef37a2a 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitbox.java @@ -58,7 +58,7 @@ public class ShulkerFurnitureHitbox extends AbstractFurnitureHitBox { entityIds[1], UUID.randomUUID(), x + offset.x, processedY, z - offset.z, 0, yaw, MEntityTypes.SHULKER, 0, CoreReflections.instance$Vec3$Zero, 0 )); - packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.copyOf(config.cachedShulkerValues()))); + packets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], config.cachedShulkerValues())); packets.add(FastNMS.INSTANCE.constructor$ClientboundSetPassengersPacket(entityIds[0], entityIds[1])); // fix some special occasions diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitboxConfig.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitboxConfig.java index 004b73d26..4ca6e465a 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitboxConfig.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerFurnitureHitboxConfig.java @@ -66,6 +66,7 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig< ShulkerData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, this.cachedShulkerValues); // Invisible List cachedInteractionValues = new ArrayList<>(); + InteractionEntityData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, cachedInteractionValues); float shulkerHeight = (getPhysicalPeek(peek * 0.01F) + 1) * scale; if (direction == Direction.UP) { InteractionEntityData.Height.addEntityDataIfNotDefaultValue(shulkerHeight + 0.01f, cachedInteractionValues); @@ -81,7 +82,7 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig< packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(cachedInteractionValues))); if (canUseItemOn) { Vec3d vec3d = new Vec3d(x + offset.x, y + offset.y, z - offset.z); - aabb.accept(new FurnitureHitboxPart(entityIds[2], AABB.fromInteraction(vec3d, scale, shulkerHeight), vec3d)); + aabb.accept(new FurnitureHitboxPart(entityIds[2], AABB.fromInteraction(vec3d, scale, shulkerHeight), vec3d, interactive)); } } }; @@ -101,7 +102,7 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig< packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(cachedInteractionValues))); if (canUseItemOn) { Vec3d vec3d = new Vec3d(x + offset.x, y + offset.y - shulkerHeight + scale, z - offset.z); - aabb.accept(new FurnitureHitboxPart(entityIds[2], AABB.fromInteraction(vec3d, scale, shulkerHeight), vec3d)); + aabb.accept(new FurnitureHitboxPart(entityIds[2], AABB.fromInteraction(vec3d, scale, shulkerHeight), vec3d, interactive)); } } }; @@ -132,8 +133,8 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig< if (canUseItemOn) { Vec3d vec3d1 = new Vec3d(x + offset.x, y + offset.y, z - offset.z); Vec3d vec3d2 = new Vec3d(x + offset.x + shulkerDirection.stepX() * distance, y + offset.y, z - offset.z + shulkerDirection.stepZ() * distance); - aabb.accept(new FurnitureHitboxPart(entityIds[2], AABB.fromInteraction(vec3d1, scale, scale), vec3d1)); - aabb.accept(new FurnitureHitboxPart(entityIds[3], AABB.fromInteraction(vec3d2, scale, scale), vec3d2)); + aabb.accept(new FurnitureHitboxPart(entityIds[2], AABB.fromInteraction(vec3d1, scale, scale), vec3d1, interactive)); + aabb.accept(new FurnitureHitboxPart(entityIds[3], AABB.fromInteraction(vec3d2, scale, scale), vec3d2, interactive)); } } }; @@ -159,31 +160,31 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig< } public float scale() { - return scale; + return this.scale; } public byte peek() { - return peek; + return this.peek; } public boolean interactive() { - return interactive; + return this.interactive; } public boolean interactionEntity() { - return interactionEntity; + return this.interactionEntity; } public Direction direction() { - return direction; + return this.direction; } public DirectionalShulkerSpawner spawner() { - return spawner; + return this.spawner; } public List cachedShulkerValues() { - return cachedShulkerValues; + return this.cachedShulkerValues; } @Override @@ -219,7 +220,7 @@ public class ShulkerFurnitureHitboxConfig extends AbstractFurnitureHitBoxConfig< AABB ceAABB = createAABB(direction, offset, x, y, z); Object level = world.serverWorld(); Object nmsAABB = FastNMS.INSTANCE.constructor$AABB(ceAABB.minX, ceAABB.minY, ceAABB.minZ, ceAABB.maxX, ceAABB.maxY, ceAABB.maxZ); - aabb.accept(new FurnitureHitboxPart(entityId, ceAABB, new Vec3d(x, y, z))); + aabb.accept(new FurnitureHitboxPart(entityId, ceAABB, new Vec3d(x, y, z), false)); return new BukkitCollider(level, nmsAABB, x, y, z, this.canBeHitByProjectile(), true, this.blocksBuilding()); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java index 578925913..afa959aec 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/BukkitNetworkManager.java @@ -3826,6 +3826,9 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes for (Seat seat : hitBox.seats()) { if (!seat.isOccupied()) { if (seat.spawnSeat(serverPlayer, furniture.position())) { + if (!part.interactive()) { + serverPlayer.swingHand(InteractionHand.MAIN_HAND); + } break; } } diff --git a/common-files/src/main/resources/resources/default/configuration/furniture/wooden_chair.yml b/common-files/src/main/resources/resources/default/configuration/furniture/wooden_chair.yml index 9ea08846d..354d39baf 100644 --- a/common-files/src/main/resources/resources/default/configuration/furniture/wooden_chair.yml +++ b/common-files/src/main/resources/resources/default/configuration/furniture/wooden_chair.yml @@ -29,6 +29,7 @@ items: - position: 0,0,0 type: interaction blocks-building: true + invisible: true width: 0.7 height: 1.2 interactive: true diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/hitbox/FurnitureHitboxPart.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/hitbox/FurnitureHitboxPart.java index e69a747f5..acf13acd3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/hitbox/FurnitureHitboxPart.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/hitbox/FurnitureHitboxPart.java @@ -3,5 +3,5 @@ package net.momirealms.craftengine.core.entity.furniture.hitbox; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.collision.AABB; -public record FurnitureHitboxPart(int entityId, AABB aabb, Vec3d pos) { +public record FurnitureHitboxPart(int entityId, AABB aabb, Vec3d pos, boolean interactive) { }