mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-23 08:59:27 +00:00
added collider
This commit is contained in:
@@ -9,7 +9,6 @@ import net.momirealms.craftengine.core.entity.furniture.ItemDisplayContext;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.QuaternionUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.joml.Quaternionf;
|
||||
@@ -34,9 +33,9 @@ public class BukkitFurnitureElement extends AbstractFurnitureElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawnPackets(int entityId, double x, double y, double z, float yaw, Consumer<Object> packets) {
|
||||
public void addSpawnPackets(int entityId, double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<Object> packets) {
|
||||
try {
|
||||
Vector3f offset = QuaternionUtils.toQuaternionf(0, Math.toRadians(180 - yaw), 0).conjugate().transform(new Vector3f(position()));
|
||||
Vector3f offset = conjugated.transform(new Vector3f(position()));
|
||||
packets.accept(Reflections.constructor$ClientboundAddEntityPacket.newInstance(
|
||||
entityId, UUID.randomUUID(), x + offset.x, y + offset.y, z - offset.z, 0, yaw,
|
||||
Reflections.instance$EntityType$ITEM_DISPLAY, 0, Reflections.instance$Vec3$Zero, 0
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.hitbox.InteractionHitBox;
|
||||
import net.momirealms.craftengine.bukkit.nms.CollisionEntity;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
@@ -145,10 +144,9 @@ public class BukkitFurnitureManager implements FurnitureManager {
|
||||
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("width") && !config.containsKey("height")) {
|
||||
if (!config.containsKey("position")) {
|
||||
colliders.add(new Collider(
|
||||
(boolean) config.getOrDefault("can-be-hit-by-projectile", false),
|
||||
MiscUtils.getVector3f(config.getOrDefault("position", "0")),
|
||||
MiscUtils.getVector3f(config.getOrDefault("point-1", "0")),
|
||||
MiscUtils.getVector3f(config.getOrDefault("point-2", "0"))
|
||||
));
|
||||
@@ -234,13 +232,6 @@ public class BukkitFurnitureManager implements FurnitureManager {
|
||||
tryLeavingSeat(player, vehicle);
|
||||
}
|
||||
}
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (FastNMS.INSTANCE.method$CraftEntity$getHandle(entity) instanceof CollisionEntity) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.CollisionEntity;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.EntityUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LegacyAttributeUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
@@ -17,6 +19,7 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -55,18 +58,26 @@ public class LoadedFurniture {
|
||||
List<Integer> hitBoxEntityIds = new ArrayList<>();
|
||||
CustomFurniture.Placement placement = furniture.getPlacement(anchorType);
|
||||
|
||||
double yawInRadius = Math.toRadians(180 - this.location.getYaw());
|
||||
Quaternionf conjugated = QuaternionUtils.toQuaternionf(0, yawInRadius, 0).conjugate();
|
||||
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
double z = location.getZ();
|
||||
float yaw = this.location.getYaw();
|
||||
|
||||
List<Object> packets = new ArrayList<>();
|
||||
for (FurnitureElement element : placement.elements()) {
|
||||
int entityId = Reflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
fakeEntityIds.add(entityId);
|
||||
element.addSpawnPackets(entityId, this.location.getX(), this.location.getY(), this.location.getZ(), this.location.getYaw(), packets::add);
|
||||
element.addSpawnPackets(entityId, x, y, z, yaw, conjugated, packets::add);
|
||||
}
|
||||
for (HitBox hitBox : placement.hitBoxes()) {
|
||||
int[] ids = hitBox.acquireEntityIds(Reflections.instance$Entity$ENTITY_COUNTER::incrementAndGet);
|
||||
for (int entityId : ids) {
|
||||
fakeEntityIds.add(entityId);
|
||||
hitBoxEntityIds.add(entityId);
|
||||
hitBox.addSpawnPackets(ids, this.location.getX(), this.location.getY(), this.location.getZ(), this.location.getYaw(), packets::add);
|
||||
hitBox.addSpawnPackets(ids, x, y, z, yaw, conjugated, packets::add);
|
||||
this.hitBoxes.put(entityId, hitBox);
|
||||
}
|
||||
}
|
||||
@@ -77,6 +88,23 @@ public class LoadedFurniture {
|
||||
}
|
||||
this.fakeEntityIds = fakeEntityIds;
|
||||
this.hitBoxEntityIds = hitBoxEntityIds;
|
||||
|
||||
if (placement.colliders().length != 0) {
|
||||
Object world = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(this.location.getWorld());
|
||||
for (Collider collider : placement.colliders()) {
|
||||
Vector3f offset1 = conjugated.transform(new Vector3f(collider.point1()));
|
||||
Vector3f offset2 = conjugated.transform(new Vector3f(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();
|
||||
Object aabb = FastNMS.INSTANCE.constructor$AABB(x1, y1, z1, x2, y2, z2);
|
||||
CollisionEntity entity = FastNMS.INSTANCE.createCollisionEntity(world, aabb, x, y, z, true, collider.canBeHitByProjectile());
|
||||
FastNMS.INSTANCE.method$LevelWriter$addFreshEntity(world, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.bukkit.entity.furniture.hitbox;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -28,7 +29,7 @@ public class HappyGhastHitBox extends AbstractHitBox {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawnPackets(int[] entityId, double x, double y, double z, float yaw, Consumer<Object> packets) {
|
||||
public void addSpawnPackets(int[] entityId, double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<Object> packets) {
|
||||
// todo 乐魂
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.QuaternionUtils;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -46,8 +46,8 @@ public class InteractionHitBox extends AbstractHitBox {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawnPackets(int[] entityId, double x, double y, double z, float yaw, Consumer<Object> packets) {
|
||||
Vector3f offset = QuaternionUtils.toQuaternionf(0f, Math.toRadians(180f - yaw), 0f).conjugate().transform(new Vector3f(position()));
|
||||
public void addSpawnPackets(int[] entityId, double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<Object> packets) {
|
||||
Vector3f offset = conjugated.transform(new Vector3f(position()));
|
||||
try {
|
||||
packets.accept(Reflections.constructor$ClientboundAddEntityPacket.newInstance(
|
||||
entityId[0], UUID.randomUUID(), x + offset.x, y + offset.y, z - offset.z, 0, yaw,
|
||||
|
||||
@@ -5,7 +5,11 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.DirectionUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.entity.furniture.*;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
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 org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.*;
|
||||
@@ -46,8 +50,8 @@ public class ShulkerHitBox extends AbstractHitBox {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSpawnPackets(int[] entityIds, double x, double y, double z, float yaw, Consumer<Object> packets) {
|
||||
Vector3f offset = QuaternionUtils.toQuaternionf(0f, Math.toRadians(180f - yaw), 0f).conjugate().transform(new Vector3f(position()));
|
||||
public void addSpawnPackets(int[] entityIds, double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<Object> packets) {
|
||||
Vector3f offset = conjugated.transform(new Vector3f(position()));
|
||||
try {
|
||||
packets.accept(Reflections.constructor$ClientboundAddEntityPacket.newInstance(
|
||||
entityIds[0], UUID.randomUUID(), x + offset.x, y + offset.y, z - offset.z, 0, yaw,
|
||||
|
||||
@@ -3,21 +3,18 @@ package net.momirealms.craftengine.core.entity.furniture;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class Collider {
|
||||
private final Vector3f position;
|
||||
private final Vector3f point1;
|
||||
private final Vector3f point2;
|
||||
private final boolean canBeHitByProjectile;
|
||||
|
||||
public Collider(boolean canBeHitByProjectile, Vector3f position, Vector3f point1, Vector3f point2) {
|
||||
public Collider(boolean canBeHitByProjectile, Vector3f point1, Vector3f point2) {
|
||||
this.canBeHitByProjectile = canBeHitByProjectile;
|
||||
this.position = position;
|
||||
this.point1 = point1;
|
||||
this.point2 = point2;
|
||||
}
|
||||
|
||||
public Collider(boolean canBeHitByProjectile, Vector3f position, float width, float height) {
|
||||
this.canBeHitByProjectile = canBeHitByProjectile;
|
||||
this.position = position;
|
||||
this.point1 = new Vector3f(position.x - width / 2, position.y, position.z - width / 2);
|
||||
this.point2 = new Vector3f(position.x + width / 2, position.y + height, position.z + width / 2);
|
||||
}
|
||||
@@ -26,10 +23,6 @@ public class Collider {
|
||||
return canBeHitByProjectile;
|
||||
}
|
||||
|
||||
public Vector3f position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector3f point1() {
|
||||
return point1;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ public interface FurnitureElement {
|
||||
|
||||
Vector3f position();
|
||||
|
||||
void addSpawnPackets(int entityId, double x, double y, double z, float yaw, Consumer<Object> packets);
|
||||
void addSpawnPackets(int entityId, double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<Object> packets);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@@ -10,7 +11,7 @@ public interface HitBox {
|
||||
|
||||
Key type();
|
||||
|
||||
void addSpawnPackets(int[] entityId, double x, double y, double z, float yaw, Consumer<Object> packets);
|
||||
void addSpawnPackets(int[] entityId, double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<Object> packets);
|
||||
|
||||
int[] acquireEntityIds(Supplier<Integer> entityIdSupplier);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ mojang_brigadier_version=1.0.18
|
||||
byte_buddy_version=1.15.11
|
||||
snake_yaml_version=2.3
|
||||
anti_grief_version=0.13
|
||||
nms_helper_version=0.21
|
||||
nms_helper_version=0.22
|
||||
# Ignite Dependencies
|
||||
mixinextras_version=0.4.1
|
||||
mixin_version=0.15.2+mixin.0.8.7
|
||||
|
||||
Reference in New Issue
Block a user