9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-29 03:49:15 +00:00

try fixing hitbox

This commit is contained in:
XiaoMoMi
2025-04-01 21:29:50 +08:00
parent f53f5a9166
commit fde833e862
6 changed files with 37 additions and 35 deletions

View File

@@ -135,24 +135,24 @@ public class BukkitFurnitureManager implements FurnitureManager {
}
// add colliders
List<Map<String, Object>> colliderConfigs = (List<Map<String, Object>>) placementArguments.getOrDefault("colliders", List.of());
List<Collider> colliders = new ArrayList<>();
for (Map<String, Object> config : colliderConfigs) {
if (!config.containsKey("position")) {
colliders.add(new Collider(
(boolean) config.getOrDefault("can-be-hit-by-projectile", false),
MiscUtils.getVector3d(config.getOrDefault("point-1", "0")),
MiscUtils.getVector3d(config.getOrDefault("point-2", "0"))
));
} else {
colliders.add(new Collider(
(boolean) config.getOrDefault("can-be-hit-by-projectile", false),
MiscUtils.getVector3f(config.getOrDefault("position", "0")),
MiscUtils.getAsFloat(config.getOrDefault("width", "1")),
MiscUtils.getAsFloat(config.getOrDefault("height", "1"))
));
}
}
// List<Map<String, Object>> colliderConfigs = (List<Map<String, Object>>) placementArguments.getOrDefault("colliders", List.of());
// for (Map<String, Object> config : colliderConfigs) {
// if (!config.containsKey("position")) {
// colliders.add(new Collider(
// (boolean) config.getOrDefault("can-be-hit-by-projectile", false),
// MiscUtils.getVector3d(config.getOrDefault("point-1", "0")),
// MiscUtils.getVector3d(config.getOrDefault("point-2", "0"))
// ));
// } else {
// colliders.add(new Collider(
// (boolean) config.getOrDefault("can-be-hit-by-projectile", false),
// MiscUtils.getVector3f(config.getOrDefault("position", "0")),
// MiscUtils.getAsFloat(config.getOrDefault("width", "1")),
// MiscUtils.getAsFloat(config.getOrDefault("height", "1"))
// ));
// }
// }
// external model providers
Optional<ExternalModel> externalModel;

View File

@@ -127,16 +127,17 @@ public class LoadedFurniture {
Object world = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(this.location.getWorld());
for (int i = 0; i < colliderSize; i++) {
Collider collider = placement.colliders()[i];
Vector3d offset1 = conjugated.transform(new Vector3d(collider.point1()));
Vector3d offset2 = conjugated.transform(new Vector3d(collider.point2()));
double x1 = x + offset1.x();
double x2 = x + offset2.x();
double y1 = y + offset1.y();
double y2 = y + offset2.y();
double z1 = z - offset1.z();
double z2 = z - offset2.z();
Vector3f offset = conjugated.transform(collider.position());
Vector3d offset1 = collider.point1();
Vector3d offset2 = collider.point2();
double x1 = x + offset1.x() + offset.x();
double x2 = x + offset2.x() + offset.x();
double y1 = y + offset1.y() + offset.y();
double y2 = y + offset2.y() + offset.y();
double z1 = z - offset1.z() + offset.z();
double z2 = z - offset2.z() + offset.z();
Object aabb = FastNMS.INSTANCE.constructor$AABB(x1, y1, z1, x2, y2, z2);
CollisionEntity entity = FastNMS.INSTANCE.createCollisionEntity(world, aabb, x, y, z, collider.canBeHitByProjectile());
CollisionEntity entity = FastNMS.INSTANCE.createCollisionShulker(world, aabb, x, y, z, collider.canBeHitByProjectile());
FastNMS.INSTANCE.method$LevelWriter$addFreshEntity(world, entity);
this.collisionEntities[i] = entity;
}

View File

@@ -80,8 +80,9 @@ public class ShulkerHitBox extends AbstractHitBox {
}
return Optional.of(new Collider(
true,
new Vector3d(x1 + position.x, y1 + position.y, z1 + position.z),
new Vector3d(x2 + position.x, y2 + position.y, z2 + position.z)
position,
new Vector3d(x1, y1, z1),
new Vector3d(x2, y2, z2)
));
}

View File

@@ -625,7 +625,7 @@ public class PacketConsumers {
event.setCancelled(true);
}
}
} else if (entityType == Reflections.instance$EntityType$INTERACTION) {
} else if (entityType == Reflections.instance$EntityType$SHULKER) {
// Cancel collider entity packet
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
LoadedFurniture furniture = BukkitFurnitureManager.instance().getLoadedFurnitureByCollisionEntityId(entityId);