mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
fix(bukkit): 修复玩家载具坐骑问题
This commit is contained in:
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.bukkit.entity.furniture;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.bettermodel.BetterModelModel;
|
||||
import net.momirealms.craftengine.bukkit.compatibility.modelengine.ModelEngineModel;
|
||||
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;
|
||||
@@ -26,6 +27,7 @@ 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;
|
||||
@@ -42,6 +44,7 @@ public class BukkitFurnitureManager implements FurnitureManager {
|
||||
|
||||
private final Map<Integer, LoadedFurniture> furnitureByBaseEntityId = new ConcurrentHashMap<>(256, 0.5f);
|
||||
private final Map<Integer, LoadedFurniture> furnitureByEntityId = new ConcurrentHashMap<>(512, 0.5f);
|
||||
private final Map<Integer, LoadedFurniture> furnitureByCollisionEntitiesId = new ConcurrentHashMap<>(256, 0.5f);
|
||||
// Event listeners
|
||||
private final Listener dismountListener;
|
||||
private final FurnitureEventListener furnitureEventListener;
|
||||
@@ -270,6 +273,11 @@ public class BukkitFurnitureManager implements FurnitureManager {
|
||||
return this.furnitureByEntityId.get(entityId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LoadedFurniture getLoadedFurnitureByCollisionEntityId(int entityId) {
|
||||
return this.furnitureByCollisionEntitiesId.get(entityId);
|
||||
}
|
||||
|
||||
protected void handleBaseFurnitureUnload(Entity entity) {
|
||||
int id = entity.getEntityId();
|
||||
LoadedFurniture furniture = this.furnitureByBaseEntityId.remove(id);
|
||||
@@ -348,6 +356,14 @@ public class BukkitFurnitureManager implements FurnitureManager {
|
||||
for (int entityId : loadedFurniture.entityIds()) {
|
||||
this.furnitureByEntityId.put(entityId, loadedFurniture);
|
||||
}
|
||||
for (CollisionEntity collisionEntity : loadedFurniture.collisionEntities()) {
|
||||
try {
|
||||
int collisionEntityId = (int) Reflections.method$Entity$getId.invoke(collisionEntity);
|
||||
this.furnitureByCollisionEntitiesId.put(collisionEntityId, loadedFurniture);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return loadedFurniture;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,6 +240,10 @@ public class LoadedFurniture {
|
||||
return Collections.unmodifiableList(this.fakeEntityIds);
|
||||
}
|
||||
|
||||
public CollisionEntity[] collisionEntities() {
|
||||
return this.collisionEntities;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnchorType anchorType() {
|
||||
return this.anchorType;
|
||||
|
||||
@@ -626,9 +626,13 @@ public class PacketConsumers {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} else if (entityType.equals(CollisionEntity.class)) {
|
||||
} else if (entityType == Reflections.instance$EntityType$INTERACTION) {
|
||||
// 取消服务端碰撞实体
|
||||
event.setCancelled(true);
|
||||
int entityId = (int) Reflections.field$ClientboundAddEntityPacket$entityId.get(packet);
|
||||
LoadedFurniture furniture = BukkitFurnitureManager.instance().getLoadedFurnitureByCollisionEntityId(entityId);
|
||||
if (furniture != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundAddEntityPacket", e);
|
||||
|
||||
@@ -5917,4 +5917,16 @@ public class Reflections {
|
||||
clazz$CraftEntity, clazz$Entity, 0
|
||||
)
|
||||
);
|
||||
|
||||
public static final Method method$Entity$getId = requireNonNull(
|
||||
VersionHelper.isVersionNewerThan1_20_5()
|
||||
? ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"getId"})
|
||||
: VersionHelper.isVersionNewerThan1_20_3()
|
||||
? ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"aj"})
|
||||
: VersionHelper.isVersionNewerThan1_20_2()
|
||||
? ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"ah"})
|
||||
: VersionHelper.isVersionNewerThan1_20()
|
||||
? ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"af"})
|
||||
: ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"getId", "aj", "ah", "af"})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user