9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 10:59:07 +00:00

修改算法

This commit is contained in:
XiaoMoMi
2025-04-01 19:44:21 +08:00
parent c59dc8ed15
commit 883c723ea5
6 changed files with 53 additions and 27 deletions

View File

@@ -49,7 +49,7 @@ command.item.get.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0
command.item.give.success.single: "<lang:commands.give.success.single:'<arg:0>':'<arg:1>':'<arg:2>'>"
command.item.give.success.multiple: "<lang:commands.give.success.multiple:'<arg:0>':'<arg:1>':'<arg:2>'>"
command.item.give.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0>'></red>"
command.item.recipe.browser.recipe.no_found: "<red>找不到此物品的配方</red>"
command.item.usage.browser.recipe.no_found: "<red>找不到此物品的用</red>"
command.search_recipe.not_found: "<red>找不到此物品的配方</red>"
command.search_usage.not_found: "<red>找不到此物品的用</red>"
command.search_recipe.no_item: "<red>请手持物品后再执行此命令</red>"
command.search_usage.no_item: "<red>请手持物品后再执行此命令</red>"

View File

@@ -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<String, Object> 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);

View File

@@ -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<Object> cachedShulkerValues = new ArrayList<>();
private final List<Object> 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<Collider> optionCollider() {
public Optional<Collider> 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<String, Object> 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);

View File

@@ -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);

View File

@@ -20,7 +20,7 @@ public interface HitBox {
Vector3f position();
default Optional<Collider> optionCollider() {
default Optional<Collider> optionalCollider() {
return Optional.empty();
}
}

View File

@@ -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> T findNextInIterable(Iterable<T> iterable, @Nullable T object) {
Iterator<T> iterator = iterable.iterator();
T next = iterator.next();