From 42850376ff1fc23e988aff4c131f9d56eafbc617 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sat, 19 Apr 2025 19:46:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E5=B8=A6=E6=96=B9=E5=90=91?= =?UTF-8?q?=E7=9A=84=E6=BD=9C=E5=BD=B1=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/furniture/hitbox/CustomHitBox.java | 1 - .../furniture/hitbox/ShulkerHitBox.java | 108 ++++++++++++------ .../item/behavior/BoneMealItemBehavior.java | 1 - .../bukkit/plugin/BukkitCraftEngine.java | 1 - .../plugin/command/feature/TestCommand.java | 1 - .../core/pack/host/impl/DropboxHost.java | 30 +++-- 6 files changed, 92 insertions(+), 50 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java index df0452f58..fd98180ca 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java @@ -1,7 +1,6 @@ package net.momirealms.craftengine.bukkit.entity.furniture.hitbox; import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData; - import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.util.Reflections; import net.momirealms.craftengine.core.entity.furniture.*; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java index 7ad58dff3..4835d991f 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/ShulkerHitBox.java @@ -25,8 +25,7 @@ public class ShulkerHitBox extends AbstractHitBox { private final boolean interactionEntity; private final Direction direction; private final List cachedShulkerValues = new ArrayList<>(); - private final List cachedInteractionValues = new ArrayList<>(); - private final float yOffset; + private final DirectionalShulkerSpawner spawner; public ShulkerHitBox(Seat[] seats, Vector3f position, Direction direction, float scale, byte peek, boolean interactionEntity, boolean interactive) { super(seats, position); @@ -40,22 +39,67 @@ public class ShulkerHitBox extends AbstractHitBox { ShulkerData.Color.addEntityDataIfNotDefaultValue((byte) 0, this.cachedShulkerValues); ShulkerData.NoGravity.addEntityDataIfNotDefaultValue(true, this.cachedShulkerValues); ShulkerData.Silent.addEntityDataIfNotDefaultValue(true, this.cachedShulkerValues); - ShulkerData.MobFlags.addEntityDataIfNotDefaultValue((byte) 0x01, this.cachedShulkerValues); // 无ai -// ShulkerData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, this.cachedShulkerValues); // 不可见 + ShulkerData.MobFlags.addEntityDataIfNotDefaultValue((byte) 0x01, this.cachedShulkerValues); // NO AI + ShulkerData.SharedFlags.addEntityDataIfNotDefaultValue((byte) 0x20, this.cachedShulkerValues); // Invisible float shulkerHeight = (getPhysicalPeek(peek * 0.01F) + 1) * scale; - - if (this.interactionEntity) { - // make it a litter bigger + List cachedInteractionValues = new ArrayList<>(); + if (this.direction == Direction.UP) { + Collider c = createCollider(Direction.UP); InteractionEntityData.Height.addEntityDataIfNotDefaultValue(shulkerHeight + 0.01f, cachedInteractionValues); InteractionEntityData.Width.addEntityDataIfNotDefaultValue(scale + 0.005f, cachedInteractionValues); InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(interactive, cachedInteractionValues); - } - - if (this.direction == Direction.DOWN) { - this.yOffset = -shulkerHeight + 1; + this.spawner = (entityIds, x, y, z, yaw, offset, packets, collider) -> { + collider.accept(c); + if (interactionEntity) { + packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( + entityIds[2], UUID.randomUUID(), x + offset.x, y + offset.y - 0.005f, z - offset.z, 0, yaw, + Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 + ), true); + packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(cachedInteractionValues)), true); + } + }; + } else if (this.direction == Direction.DOWN) { + Collider c = createCollider(Direction.DOWN); + InteractionEntityData.Height.addEntityDataIfNotDefaultValue(shulkerHeight + 0.01f, cachedInteractionValues); + InteractionEntityData.Width.addEntityDataIfNotDefaultValue(scale + 0.005f, cachedInteractionValues); + InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(interactive, cachedInteractionValues); + this.spawner = (entityIds, x, y, z, yaw, offset, packets, collider) -> { + collider.accept(c); + packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.of(ShulkerData.AttachFace.createEntityDataIfNotDefaultValue(Reflections.instance$Direction$UP))), false); + if (interactionEntity) { + packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( + entityIds[2], UUID.randomUUID(), x + offset.x, y + offset.y - 0.005f - shulkerHeight, z - offset.z, 0, yaw, + Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 + ), true); + packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(cachedInteractionValues)), true); + } + }; } else { - this.yOffset = 0; + InteractionEntityData.Height.addEntityDataIfNotDefaultValue(scale + 0.01f, cachedInteractionValues); + InteractionEntityData.Width.addEntityDataIfNotDefaultValue(scale + 0.005f, cachedInteractionValues); + InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(interactive, cachedInteractionValues); + this.spawner = (entityIds, x, y, z, yaw, offset, packets, collider) -> { + Direction shulkerAnchor = getOriginalDirection(direction, Direction.fromYaw(yaw)); + Direction shulkerDirection = shulkerAnchor.opposite(); + collider.accept(this.createCollider(shulkerDirection)); + packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.of(ShulkerData.AttachFace.createEntityDataIfNotDefaultValue(DirectionUtils.toNMSDirection(shulkerAnchor)))), false); + if (interactionEntity) { + // first interaction + packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( + entityIds[2], UUID.randomUUID(), x + offset.x, y + offset.y - 0.005f, z - offset.z, 0, yaw, + Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 + ), true); + packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(cachedInteractionValues)), true); + // second interaction + float distance = shulkerHeight - scale; + packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( + entityIds[3], UUID.randomUUID(), x + offset.x + shulkerDirection.stepX() * distance, y + offset.y - 0.005f, z - offset.z + shulkerDirection.stepZ() * distance, 0, yaw, + Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 + ), true); + packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[3], List.copyOf(cachedInteractionValues)), true); + } + }; } } @@ -156,40 +200,28 @@ public class ShulkerHitBox extends AbstractHitBox { Reflections.method$AttributeInstance$setBaseValue.invoke(attributeInstance, this.scale); packets.accept(Reflections.constructor$ClientboundUpdateAttributesPacket0.newInstance(entityIds[1], Collections.singletonList(attributeInstance)), false); } - if (this.direction == Direction.UP) { - collider.accept(this.createCollider(this.direction)); - if (this.interactionEntity) { - packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( - entityIds[2], UUID.randomUUID(), x + offset.x, y + offset.y - 0.005f, z - offset.z, 0, yaw, - Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 - ), true); - packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(this.cachedInteractionValues)), true); - } - } else if (this.direction == Direction.DOWN) { - collider.accept(this.createCollider(this.direction)); - packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.of(ShulkerData.AttachFace.createEntityDataIfNotDefaultValue(Reflections.instance$Direction$UP))), false); - if (this.interactionEntity) { - packets.accept(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket( - entityIds[2], UUID.randomUUID(), x + offset.x, y + offset.y - 0.005f + this.yOffset, z - offset.z, 0, yaw, - Reflections.instance$EntityType$INTERACTION, 0, Reflections.instance$Vec3$Zero, 0 - ), true); - packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[2], List.copyOf(this.cachedInteractionValues)), true); - } - } else { - Direction shulkerAnchor = getOriginalDirection(this.direction, Direction.fromYaw(yaw)); - collider.accept(this.createCollider(shulkerAnchor.opposite())); - packets.accept(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(entityIds[1], List.of(ShulkerData.AttachFace.createEntityDataIfNotDefaultValue(DirectionUtils.toNMSDirection(shulkerAnchor)))), false); - } + this.spawner.accept(entityIds, x, y, z, yaw, offset, packets, collider); } catch (ReflectiveOperationException e) { throw new RuntimeException("Failed to construct shulker hitbox spawn packet", e); } } + @FunctionalInterface + interface DirectionalShulkerSpawner { + + void accept(int[] entityIds, double x, double y, double z, float yaw, Vector3f offset, BiConsumer packets, Consumer collider); + } + @Override public int[] acquireEntityIds(Supplier entityIdSupplier) { if (this.interactionEntity) { - // 展示实体 // 潜影贝 // 交互实体 - return new int[] {entityIdSupplier.get(), entityIdSupplier.get(), entityIdSupplier.get()}; + if (this.direction.stepY() != 0) { + // 展示实体 // 潜影贝 // 交互实体 + return new int[] {entityIdSupplier.get(), entityIdSupplier.get(), entityIdSupplier.get()}; + } else { + // 展示实体 // 潜影贝 // 交互实体1 // 交互实体2 + return new int[] {entityIdSupplier.get(), entityIdSupplier.get(), entityIdSupplier.get(), entityIdSupplier.get()}; + } } else { // 展示实体 // 潜影贝 return new int[] {entityIdSupplier.get(), entityIdSupplier.get()}; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BoneMealItemBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BoneMealItemBehavior.java index 85b629dca..fc08fb7c6 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BoneMealItemBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/behavior/BoneMealItemBehavior.java @@ -16,7 +16,6 @@ import net.momirealms.craftengine.core.item.context.UseOnContext; import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.VersionHelper; import org.bukkit.block.Block; import java.nio.file.Path; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java index 4825024e3..891850e23 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/BukkitCraftEngine.java @@ -43,7 +43,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Pose; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/TestCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/TestCommand.java index 9804bb208..cafb24cdf 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/TestCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/TestCommand.java @@ -5,7 +5,6 @@ import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.entity.Pose; import org.incendo.cloud.Command; public class TestCommand extends BukkitCommandFeature { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/DropboxHost.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/DropboxHost.java index 814244b9b..f1451fa36 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/DropboxHost.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/DropboxHost.java @@ -1,16 +1,30 @@ package net.momirealms.craftengine.core.pack.host.impl; -import com.google.gson.*; -import net.momirealms.craftengine.core.pack.host.*; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import net.momirealms.craftengine.core.pack.host.ResourcePackDownloadData; +import net.momirealms.craftengine.core.pack.host.ResourcePackHost; +import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory; +import net.momirealms.craftengine.core.pack.host.ResourcePackHosts; import net.momirealms.craftengine.core.plugin.CraftEngine; -import net.momirealms.craftengine.core.util.*; -import java.io.*; -import java.net.*; -import java.net.http.*; +import net.momirealms.craftengine.core.util.GsonHelper; +import net.momirealms.craftengine.core.util.HashUtils; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.MiscUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.net.ProxySelector; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; -import java.nio.file.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; public class DropboxHost implements ResourcePackHost {