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