From 883c723ea5adf00bf7d08e1e9ede7d89652c14ba Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Tue, 1 Apr 2025 19:44:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/translations/zh_cn.yml | 4 +- .../furniture/BukkitFurnitureManager.java | 3 +- .../furniture/hitbox/ShulkerHitBox.java | 60 ++++++++++++------- .../core/entity/furniture/Collider.java | 2 +- .../core/entity/furniture/HitBox.java | 2 +- .../craftengine/core/util/MCUtils.java | 9 +++ 6 files changed, 53 insertions(+), 27 deletions(-) diff --git a/bukkit/loader/src/main/resources/translations/zh_cn.yml b/bukkit/loader/src/main/resources/translations/zh_cn.yml index 260aebf76..3de54b7d3 100644 --- a/bukkit/loader/src/main/resources/translations/zh_cn.yml +++ b/bukkit/loader/src/main/resources/translations/zh_cn.yml @@ -49,7 +49,7 @@ command.item.get.failure.not_exist: "':'':''>" command.item.give.success.multiple: "':'':''>" command.item.give.failure.not_exist: "'>" -command.item.recipe.browser.recipe.no_found: "找不到此物品的配方" -command.item.usage.browser.recipe.no_found: "找不到此物品的用法" +command.search_recipe.not_found: "找不到此物品的配方" +command.search_usage.not_found: "找不到此物品的用途" command.search_recipe.no_item: "请手持物品后再执行此命令" command.search_usage.no_item: "请手持物品后再执行此命令" \ No newline at end of file diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java index 55dcf71fa..1d4917204 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java @@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull; import org.joml.Vector3f; import javax.annotation.Nullable; -import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -171,7 +170,7 @@ public class BukkitFurnitureManager implements FurnitureManager { for (Map config : hitboxConfigs) { HitBox hitBox = HitBoxTypes.fromMap(config); hitboxes.add(hitBox); - hitBox.optionCollider().ifPresent(colliders::add); + hitBox.optionalCollider().ifPresent(colliders::add); } if (hitboxes.isEmpty() && externalModel.isEmpty()) { hitboxes.add(InteractionHitBox.DEFAULT); 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 105c6305c..5da5ebc01 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 @@ -5,11 +5,9 @@ import net.momirealms.craftengine.bukkit.entity.data.ShulkerData; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.util.Reflections; import net.momirealms.craftengine.core.entity.furniture.*; -import net.momirealms.craftengine.core.util.Direction; -import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.MiscUtils; -import net.momirealms.craftengine.core.util.VersionHelper; +import net.momirealms.craftengine.core.util.*; import org.joml.Quaternionf; +import org.joml.Vector3d; import org.joml.Vector3f; import java.util.*; @@ -20,7 +18,7 @@ import java.util.function.Supplier; public class ShulkerHitBox extends AbstractHitBox { public static final Factory FACTORY = new Factory(); // 1.20.6+ - private final double scale; + private final float scale; private final byte peek; private final boolean interactive; private final boolean interactionEntity; @@ -29,7 +27,7 @@ public class ShulkerHitBox extends AbstractHitBox { private final List cachedShulkerValues = new ArrayList<>(); private final List cachedInteractionValues = new ArrayList<>(); - public ShulkerHitBox(Seat[] seats, Vector3f position, double scale, byte peek, boolean interactionEntity, boolean interactive) { + public ShulkerHitBox(Seat[] seats, Vector3f position, float scale, byte peek, boolean interactionEntity, boolean interactive) { super(seats, position); this.scale = scale; this.peek = peek; @@ -46,29 +44,49 @@ public class ShulkerHitBox extends AbstractHitBox { if (this.interactionEntity) { // make it a litter bigger - InteractionEntityData.Height.addEntityDataIfNotDefaultValue(getPeekHeight(peek, scale) + 0.01f, cachedInteractionValues); - InteractionEntityData.Width.addEntityDataIfNotDefaultValue((float) scale + 0.01f, cachedInteractionValues); + InteractionEntityData.Height.addEntityDataIfNotDefaultValue(getPhysicalPeek(peek) * scale + 0.01f, cachedInteractionValues); + InteractionEntityData.Width.addEntityDataIfNotDefaultValue(scale + 0.01f, cachedInteractionValues); InteractionEntityData.Responsive.addEntityDataIfNotDefaultValue(interactive, cachedInteractionValues); } } @Override - public Optional optionCollider() { + public Optional optionalCollider() { + float peek = getPhysicalPeek(this.peek() * 0.01F); + double x1 = -scale * 0.5; + double y1 = 0.0; + double z1 = -scale * 0.5; + double x2 = scale * 0.5; + double y2 = scale; + double z2 = scale * 0.5; + + double dx = (double) direction.stepX() * peek * (double) scale; + if (dx > 0) { + x2 += dx; + } else if (dx < 0) { + x1 += dx; + } + double dy = (double) direction.stepY() * peek * (double) scale; + if (dy > 0) { + y2 += dy; + } else if (dy < 0) { + y1 += dy; + } + double dz = (double) direction.stepZ() * peek * (double) scale; + if (dz > 0) { + z2 += dz; + } else if (dz < 0) { + z1 += dz; + } return Optional.of(new Collider( true, - position(), - (float) scale(), - getPeekHeight(peek(), scale()) + new Vector3d(x1, y1, z1), + new Vector3d(x2, y2, z2) )); } - private static float getPeekHeight(byte peek, double scale) { - double sineValue = Math.sin( - (0.5 + peek * 0.01) * Math.PI - ); - return (float) ( - (1.0 + (0.5 - sineValue * 0.5)) * scale - ); + private static float getPhysicalPeek(float peek) { + return 0.5F - MCUtils.sin((0.5F + peek) * 3.1415927F) * 0.5F; } public boolean interactionEntity() { @@ -87,7 +105,7 @@ public class ShulkerHitBox extends AbstractHitBox { return peek; } - public double scale() { + public float scale() { return scale; } @@ -144,7 +162,7 @@ public class ShulkerHitBox extends AbstractHitBox { @Override public HitBox create(Map arguments) { Vector3f position = MiscUtils.getVector3f(arguments.getOrDefault("position", "0")); - double scale = MiscUtils.getAsDouble(arguments.getOrDefault("scale", "1")); + float scale = MiscUtils.getAsFloat(arguments.getOrDefault("scale", "1")); byte peek = (byte) MiscUtils.getAsInt(arguments.getOrDefault("peek", 0)); Direction directionEnum = Optional.ofNullable(arguments.get("direction")).map(it -> Direction.valueOf(it.toString().toUpperCase(Locale.ENGLISH))).orElse(Direction.UP); boolean interactive = (boolean) arguments.getOrDefault("interactive", true); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/Collider.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/Collider.java index efa419157..dd2b73c7c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/Collider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/Collider.java @@ -14,7 +14,7 @@ public class Collider { this.point2 = point2; } - public Collider(boolean canBeHitByProjectile, Vector3f position, float width, float height) { + public Collider(boolean canBeHitByProjectile, Vector3f position, double width, double height) { this.canBeHitByProjectile = canBeHitByProjectile; this.point1 = new Vector3d(position.x - width / 2, position.y, position.z - width / 2); this.point2 = new Vector3d(position.x + width / 2, position.y + height, position.z + width / 2); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java index 3978e2f20..2dc98a150 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBox.java @@ -20,7 +20,7 @@ public interface HitBox { Vector3f position(); - default Optional optionCollider() { + default Optional optionalCollider() { return Optional.empty(); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/MCUtils.java b/core/src/main/java/net/momirealms/craftengine/core/util/MCUtils.java index 37beb52dd..9669fe006 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/MCUtils.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/MCUtils.java @@ -13,6 +13,11 @@ public class MCUtils { private MCUtils() {} private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; + private static final float[] SIN = make(new float[65536], (sineTable) -> { + for(int i = 0; i < sineTable.length; ++i) { + sineTable[i] = (float) Math.sin((double) i * Math.PI * 2.0 / 65536.0); + } + }); public static int fastFloor(double value) { int truncated = (int) value; @@ -159,6 +164,10 @@ public class MCUtils { return previous; } + public static float sin(float value) { + return SIN[(int) (value * 10430.378F) & '\uffff']; + } + public static T findNextInIterable(Iterable iterable, @Nullable T object) { Iterator iterator = iterable.iterator(); T next = iterator.next();