mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
修改库类加载器
This commit is contained in:
@@ -129,13 +129,12 @@ public final class BukkitCustomBlock extends AbstractCustomBlock {
|
||||
// set block side properties
|
||||
CoreReflections.field$BlockBehaviour$explosionResistance.set(nmsBlock, settings.resistance());
|
||||
CoreReflections.field$BlockBehaviour$soundType.set(nmsBlock, SoundUtils.toSoundType(settings.sounds()));
|
||||
// 1.21.2以前要在init cache之前设定 isConditionallyFullOpaque
|
||||
// init cache
|
||||
CoreReflections.method$BlockStateBase$initCache.invoke(nmsState);
|
||||
boolean isConditionallyFullOpaque = canOcclude & useShapeForLightOcclusion;
|
||||
if (!VersionHelper.isOrAbove1_21_2()) {
|
||||
CoreReflections.field$BlockStateBase$isConditionallyFullOpaque.set(nmsState, isConditionallyFullOpaque);
|
||||
}
|
||||
// init cache
|
||||
CoreReflections.method$BlockStateBase$initCache.invoke(nmsState);
|
||||
// modify cache
|
||||
if (VersionHelper.isOrAbove1_21_2()) {
|
||||
int blockLight = settings.blockLight() != -1 ? settings.blockLight() : CoreReflections.field$BlockStateBase$lightBlock.getInt(immutableBlockState.vanillaBlockState().handle());
|
||||
|
||||
@@ -18,29 +18,38 @@ public class PaperClassPathAppender implements ClassPathAppender {
|
||||
public static final Field field$PaperPluginClassLoader$libraryLoader = Optional.ofNullable(clazz$PaperPluginClassLoader)
|
||||
.map(it -> ReflectionUtils.getDeclaredField(it, URLClassLoader.class, 0))
|
||||
.orElse(null);
|
||||
private final URLClassLoaderAccess classLoaderAccess;
|
||||
private final URLClassLoaderAccess libraryClassLoaderAccess;
|
||||
|
||||
// todo 是否有更好的方法让库被其他插件共享
|
||||
public PaperClassPathAppender(ClassLoader classLoader) {
|
||||
// 25/7/26 往Bukkit类加载器里硬灌,就能保证库也被其他插件使用了
|
||||
this.classLoaderAccess = URLClassLoaderAccess.create((URLClassLoader) Bukkit.class.getClassLoader());
|
||||
// try {
|
||||
// if (clazz$PaperPluginClassLoader != null && clazz$PaperPluginClassLoader.isInstance(classLoader)) {
|
||||
// URLClassLoader libraryClassLoader = (URLClassLoader) field$PaperPluginClassLoader$libraryLoader.get(classLoader);
|
||||
// this.classLoaderAccess = URLClassLoaderAccess.create(libraryClassLoader);
|
||||
// } else if (classLoader instanceof URLClassLoader) {
|
||||
// this.classLoaderAccess = URLClassLoaderAccess.create((URLClassLoader) classLoader);
|
||||
// } else {
|
||||
// throw new IllegalStateException("ClassLoader is not instance of URLClassLoader");
|
||||
// }
|
||||
// } catch (ReflectiveOperationException e) {
|
||||
// throw new RuntimeException("Failed to instantiate PaperPluginClassLoader", e);
|
||||
// }
|
||||
// 这个类加载器用于加载重定位后的依赖库,这样所有插件都能访问到
|
||||
ClassLoader bukkitClassLoader = Bukkit.class.getClassLoader();
|
||||
if (bukkitClassLoader instanceof URLClassLoader urlClassLoader) {
|
||||
this.libraryClassLoaderAccess = URLClassLoaderAccess.create(urlClassLoader);
|
||||
} else {
|
||||
// ignite会把Bukkit放置于EmberClassLoader中,获取其父DynamicClassLoader
|
||||
if (bukkitClassLoader.getClass().getName().equals("space.vectrix.ignite.launch.ember.EmberClassLoader") && bukkitClassLoader.getParent() instanceof URLClassLoader urlClassLoader) {
|
||||
this.libraryClassLoaderAccess = URLClassLoaderAccess.create(urlClassLoader);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 最次的方案,使用paper自带的classloader去加载依赖,这种情况会发生依赖隔离
|
||||
if (clazz$PaperPluginClassLoader != null && clazz$PaperPluginClassLoader.isInstance(classLoader)) {
|
||||
URLClassLoader libraryClassLoader = (URLClassLoader) field$PaperPluginClassLoader$libraryLoader.get(classLoader);
|
||||
this.libraryClassLoaderAccess = URLClassLoaderAccess.create(libraryClassLoader);
|
||||
} else {
|
||||
throw new IllegalStateException("ClassLoader is not instance of URLClassLoader");
|
||||
}
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Failed to instantiate PaperPluginClassLoader", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addJarToClasspath(Path file) {
|
||||
try {
|
||||
this.classLoaderAccess.addURL(file.toUri().toURL());
|
||||
this.libraryClassLoaderAccess.addURL(file.toUri().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class BlockStateGenerator {
|
||||
if (vec3 == null) return List.of();
|
||||
|
||||
Object tool = FastNMS.INSTANCE.method$LootParams$Builder$getOptionalParameter(builder, MLootContextParams.TOOL);
|
||||
Item<ItemStack> item = BukkitItemManager.instance().wrap(tool == null || FastNMS.INSTANCE.method$ItemStack$isEmpty(tool) ? null : FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(tool));
|
||||
Item<ItemStack> item = BukkitItemManager.instance().wrap(tool == null ? null : FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(tool));
|
||||
Object optionalPlayer = FastNMS.INSTANCE.method$LootParams$Builder$getOptionalParameter(builder, MLootContextParams.THIS_ENTITY);
|
||||
if (!CoreReflections.clazz$Player.isInstance(optionalPlayer)) {
|
||||
optionalPlayer = null;
|
||||
@@ -107,7 +107,7 @@ public final class BlockStateGenerator {
|
||||
// do not drop if it's not the correct tool
|
||||
BlockSettings settings = state.settings();
|
||||
if (optionalPlayer != null && settings.requireCorrectTool()) {
|
||||
if (item == null) return List.of();
|
||||
if (item.isEmpty()) return List.of();
|
||||
if (!settings.isCorrectTool(item.id()) &&
|
||||
(!settings.respectToolComponent() || !FastNMS.INSTANCE.method$ItemStack$isCorrectToolForDrops(tool, state.customBlockState().handle()))) {
|
||||
return List.of();
|
||||
|
||||
@@ -1627,7 +1627,7 @@ public class PacketConsumers {
|
||||
}
|
||||
|
||||
// 必须从网络包层面处理,否则无法获取交互的具体实体
|
||||
if (serverPlayer.isSecondaryUseActive() && itemInHand != null) {
|
||||
if (serverPlayer.isSecondaryUseActive() && !itemInHand.isEmpty()) {
|
||||
// try placing another furniture above it
|
||||
AABB hitBox = furniture.aabbByEntityId(entityId);
|
||||
if (hitBox == null) return;
|
||||
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.60.6
|
||||
project_version=0.0.60.7
|
||||
config_version=43
|
||||
lang_version=22
|
||||
project_group=net.momirealms
|
||||
|
||||
Reference in New Issue
Block a user