版本信息
你使用的系统:win10 x64
你是用的JDK: 8u251 x64
你使用的IDE:IntelliJ IDEA
你使用的IDE版本:2020.2
Forge版本: 34.1.0
Minecraft版本: 1.16.3
错误情况简述
添加Item Property Overrides
(物品属性覆盖?不知道怎么翻译好),原版1.15的ItemModelsProperties.registerProperty
方法是直接写在各个item
的构造器里面的,但是1.16被统一移到了ItemModelsProperties.java
里面。我一开始以为影响不大,结果发现如果仍然像1.15那样写咋构造器里面的话,开服务端runServer
时就会报错。
我去看了看1.16的forge文档(部分摘录在下方),基本看懂了但还是不会用 主要问题出在addPropertyOverride
方法上,一是原版和以前貌似用的是registerProperty
,二是我根本没找到这个方法。。。
报错日志
-- Head --
Thread: main
Stacktrace:
at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClassWithFlags(RuntimeDistCleaner.java:71) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-launcher.jar:34.1] {}
-- MOD rainbow6 --
Details:
Caused by 0: java.lang.ExceptionInInitializerError
at com.ussshenzhou.rainbow6.util.RegistryHandler.onItemReg(RegistryHandler.java:32) ~[classes/:?] {re:classloading}
at net.minecraftforge.eventbus.ASMEventHandler_9_RegistryHandler_onItemReg_Register.invoke(.dynamic) ~[?:?] {}
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-3.0.3-service.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297) ~[eventbus-3.0.3-service.jar:?] {}
at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:34.1] {re:classloading}
at net.minecraftforge.fml.ModContainer.lambda$null$4(ModContainer.java:112) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.registries.GameData.lambda$null$13(GameData.java:362) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$5(ModContainer.java:112) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at java.util.concurrent.CompletableFuture$AsyncRun.run$$$capture(CompletableFuture.java:1640) ~[?:1.8.0_251] {}
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java) ~[?:1.8.0_251] {}
at net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:56) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:40) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:248) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:235) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:201) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.server.ServerModLoader.load(ServerModLoader.java:44) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraft.server.Main.main(Main.java:96) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251] {}
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_251] {}
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_251] {}
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_251] {}
at net.minecraftforge.userdev.FMLUserdevServerLaunchProvider.lambda$launchService$0(FMLUserdevServerLaunchProvider.java:54) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-7.0.1.jar:?] {}
at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {}
Mod File: resources
Failure message: Rainbow6Minesiege (rainbow6) encountered an error during the load_registries event phase
java.lang.ExceptionInInitializerError: null
Mod Version: 0.1.1.dev1
Mod Issue URL: http://my.issue.tracker/
Exception message: java.lang.RuntimeException: Attempted to load class net/minecraft/client/world/ClientWorld for invalid dist DEDICATED_SERVER
Stacktrace:
at net.minecraftforge.fml.loading.RuntimeDistCleaner.processClassWithFlags(RuntimeDistCleaner.java:71) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-launcher.jar:34.1] {}
at cpw.mods.modlauncher.LaunchPluginHandler.offerClassNodeToPlugins(LaunchPluginHandler.java:85) ~[modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.ClassTransformer.transform(ClassTransformer.java:119) ~[modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.TransformingClassLoader$DelegatedClassLoader.findClass(TransformingClassLoader.java:256) ~[modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:135) ~[modlauncher-7.0.1.jar:?] {re:classloading}
at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:97) ~[modlauncher-7.0.1.jar:?] {re:classloading}
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_251] {}
此处at com.ussshenzhou.rainbow6.items.FragGrenade.<init>(FragGrenade.java:31) ~[classes/:?] {re:classloading}
at com.ussshenzhou.rainbow6.items.ModItems.<clinit>(ModItems.java:20) ~[classes/:?] {re:classloading}
at com.ussshenzhou.rainbow6.util.RegistryHandler.onItemReg(RegistryHandler.java:32) ~[classes/:?] {re:classloading}
at net.minecraftforge.eventbus.ASMEventHandler_9_RegistryHandler_onItemReg_Register.invoke(.dynamic) ~[?:?] {}
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:85) ~[eventbus-3.0.3-service.jar:?] {}
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:297) ~[eventbus-3.0.3-service.jar:?] {}
at net.minecraftforge.fml.javafmlmod.FMLModContainer.acceptEvent(FMLModContainer.java:120) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:34.1] {re:classloading}
at net.minecraftforge.fml.ModContainer.lambda$null$4(ModContainer.java:112) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.registries.GameData.lambda$null$13(GameData.java:362) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$5(ModContainer.java:112) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at java.util.concurrent.CompletableFuture$AsyncRun.run$$$capture(CompletableFuture.java:1640) ~[?:1.8.0_251] {}
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java) ~[?:1.8.0_251] {}
at net.minecraftforge.fml.ModWorkManager$SyncExecutor.driveOne(ModWorkManager.java:56) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModWorkManager$DrivenExecutor.drive(ModWorkManager.java:40) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:248) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:235) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:201) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraftforge.fml.server.ServerModLoader.load(ServerModLoader.java:44) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at net.minecraft.server.Main.main(Main.java:96) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {re:classloading}
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251] {}
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_251] {}
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_251] {}
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_251] {}
at net.minecraftforge.userdev.FMLUserdevServerLaunchProvider.lambda$launchService$0(FMLUserdevServerLaunchProvider.java:54) ~[forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-7.0.1.jar:?] {}
at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-7.0.1.jar:?] {}
at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:105) [forge-1.16.3-34.1.0_mapped_snapshot_20200916-1.16.2-recomp.jar:?] {}
相关代码
FragGrenade.java
构造器部分(1.15正常而1.16报错)
public class FragGrenade extends Item {
public FragGrenade() {
super(new Properties()
.group(ModItemGroups.Group1)
);
this.setRegistryName("fraggrenade");
ItemModelsProperties.registerProperty(ModItems.fragGrenade,new ResourceLocation("pulling"),(p_210309_0_, p_210309_1_, p_210309_2_) -> {
return p_210309_2_ != null && p_210309_2_.isHandActive() && p_210309_2_.getActiveItemStack() == p_210309_0_ ? 1.0F : 0.0F;
});
}
查到的资料
1.16.x Forge文档
Adding Properties to Items
Item::addPropertyOverride
is used to add a property to an item. TheResourceLocation
parameter is the name given to the property (e.g.new ResourceLocation("pull")
). TheIItemPropertyGetter
is a function that takes theItemStack
, theWorld
it’s in, and theEntityLivingBase
that holds it, returning thefloat
value for the property. Some examples are the"pulling"
and “pull
” properties inItemBow
, and the severalstatic final
ones inItem
. For modded item properties, it is recommended that the modid of the mod is used as the namespace (e.g.examplemod:property
and not justproperty
, as that really meansminecraft:property
).
这部分也不太明白
And here’s a hypothetical snippet from the supporting code. (This does not have to be client-only; it will work on a server too. In vanilla, properties are registered in the item’s constructor.)
item.addPropertyOverride(new IItemPropertyGetter() { @SideOnly(Side.CLIENT) @Override public float apply(ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { return (float)getPowerLevel(stack) / (float)getMaxPower(stack); // Some external methods } }