package net.my.first.mod;
import net.fabricmc.api.ModInitializer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.block.Block;
public class MyFirstMod implements ModInitializer {
public static final Item FABRIC_ITEM = new FabricItem(new Item.Settings().group(ItemGroup.MISC), null);
public static final Block FABRIC_BLOCK = new FabricBlock();
@Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("myfirstmod", "fabric_item"), FABRIC_ITEM);
Registry.register(Registry.BLOCK, new Identifier("myfirstmod", "fabric_block"), FABRIC_BLOCK);
}
}
package net.my.first.mod;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;
public class FabricItem extends Item {
public FabricItem(Settings settings, Settings item$Settings_1) {
super(item$Settings_1);
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
return new TypedActionResult<ItemStack>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand));
}
}
每当我尝试运行代码时,我总是崩溃。我正在使用Visual Studio代码,但我不明白为什么会这样,我什至尝试重新编码整个内容。这是我得到的错误:
---- Minecraft Crash Report ----
// You should try our sister game, Minceraft!
Time: 27/04/20 18:57
Description: Initializing game
net.fabricmc.loader.api.EntrypointException: Exception while loading entries for entrypoint 'main' provided by 'myfirstmod'
at net.fabricmc.loader.EntrypointStorage.getEntrypointContainers(EntrypointStorage.java:193)
at net.fabricmc.loader.FabricLoader.getEntrypointContainers(FabricLoader.java:228)
at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke0(EntrypointUtils.java:44)
at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke(EntrypointUtils.java:36)
at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointClient.start(EntrypointClient.java:32)
at net.minecraft.client.MinecraftClient.<init>(MinecraftClient.java:362)
at net.minecraft.client.main.Main.main(Main.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:192)
at net.fabricmc.loader.launch.knot.Knot.init(Knot.java:140)
at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:26)
at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at net.fabricmc.loader.util.DefaultLanguageAdapter.create(DefaultLanguageAdapter.java:45)
at net.fabricmc.loader.EntrypointStorage$NewEntry.create(EntrypointStorage.java:114)
at net.fabricmc.loader.EntrypointStorage$NewEntry.getOrCreate(EntrypointStorage.java:101)
at net.fabricmc.loader.EntrypointStorage.getEntrypointContainers(EntrypointStorage.java:186)
... 14 more
Caused by: java.lang.NullPointerException
at net.minecraft.item.Item$Settings.method_7897(Item.java:369)
at net.minecraft.item.Item.<init>(Item.java:92)
at net.my.first.mod.FabricItem.<init>(FabricItem.java:14)
at net.my.first.mod.MyFirstMod.<clinit>(MyFirstMod.java:12)
... 20 more
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Thread: Render thread
Stacktrace:
at net.fabricmc.loader.EntrypointStorage.getEntrypointContainers(EntrypointStorage.java:193)
at net.fabricmc.loader.FabricLoader.getEntrypointContainers(FabricLoader.java:228)
at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke0(EntrypointUtils.java:44)
at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointUtils.invoke(EntrypointUtils.java:36)
at net.fabricmc.loader.entrypoint.minecraft.hooks.EntrypointClient.start(EntrypointClient.java:32)
at net.minecraft.client.MinecraftClient.<init>(MinecraftClient.java:362)
-- Initialization --
Details:
Stacktrace:
at net.minecraft.client.main.Main.main(Main.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:192)
at net.fabricmc.loader.launch.knot.Knot.init(Knot.java:140)
at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:26)
at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)
-- System Details --
Details:
Minecraft Version: 1.15.2
Minecraft Version ID: 1.15.2
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_251, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 354621680 bytes (338 MB) / 570425344 bytes (544 MB) up to 1895825408 bytes (1808 MB)
CPUs: 2
JVM Flags: 3 total; -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=localhost:65427,server=n,suspend=y
Fabric Mods:
fabric: Fabric API 0.5.1+build.294-1.15
fabric-api-base: Fabric API Base 0.1.2+b7f9825d0c
fabric-biomes-v1: Fabric Biomes (v1) 0.1.5+3b05f68e0c
fabric-blockrenderlayer-v1: Fabric BlockRenderLayer Registration (v1) 1.1.4+c6a8ea890c
fabric-commands-v0: Fabric Commands (v0) 0.1.2+b7f9825d0c
fabric-containers-v0: Fabric Containers (v0) 0.1.3+b7f9825d0c
fabric-content-registries-v0: Fabric Content Registries (v0) 0.1.3+b7f9825d0c
fabric-crash-report-info-v1: Fabric Crash Report Info (v1) 0.1.2+b7f9825d0c
fabric-dimensions-v1: fabric-dimensions-v1 0.3.0+2ad156310c
fabric-events-interaction-v0: Fabric Events Interaction (v0) 0.3.0+fac69e320c
fabric-events-lifecycle-v0: Fabric Events Lifecycle (v0) 0.1.2+b7f9825d0c
fabric-item-groups-v0: Fabric Item Groups (v0) 0.1.6+ec40b2e10c
fabric-keybindings-v0: Fabric Key Bindings (v0) 0.1.1+dfdb52d60c
fabric-loot-tables-v1: Fabric Loot Tables (v1) 0.1.5+e08a73050c
fabric-mining-levels-v0: Fabric Mining Levels (v0) 0.1.1+b7f9825d0c
fabric-models-v0: Fabric Models (v0) 0.1.0+dfdb52d60c
fabric-networking-blockentity-v0: Fabric Networking Block Entity (v0) 0.2.3+e08a73050c
fabric-networking-v0: Fabric Networking (v0) 0.1.7+12515ed90c
fabric-object-builders-v0: Fabric Object Builders (v0) 0.1.3+e4c9a9c30c
fabric-particles-v1: fabric-particles-v1 0.1.1+dfdb52d60c
fabric-registry-sync-v0: Fabric Registry Sync (v0) 0.2.6+f3d8141b0c
fabric-renderer-api-v1: Fabric Renderer API (v1) 0.2.10+f08b61330c
fabric-renderer-indigo: Fabric Renderer - Indigo 0.2.23+9290e2ed0c
fabric-renderer-registries-v1: Fabric Renderer Registries (v1) 2.0.1+5a0f9a600c
fabric-rendering-data-attachment-v1: Fabric Rendering Data Attachment (v1) 0.1.3+b7f9825d0c
fabric-rendering-fluids-v1: Fabric Rendering Fluids (v1) 0.1.6+12515ed90c
fabric-rendering-v0: Fabric Rendering (v0) 1.1.0+534104900c
fabric-rendering-v1: Fabric Rendering (v1) 0.1.0+534104900c
fabric-resource-loader-v0: Fabric Resource Loader (v0) 0.1.10+06c939b30c
fabric-tag-extensions-v0: Fabric Tag Extensions (v0) 0.1.3+abd915800c
fabric-textures-v0: Fabric Textures (v0) 1.0.4+821cdba70c
fabricloader: Fabric Loader 0.8.2+build.194
minecraft: Minecraft 1.15.2
myfirstmod: My First Mod ${version}
Launched Version: Fabric
Backend library: LWJGL version 3.2.2 build 10
Backend API: NO CONTEXT
GL Caps:
Using VBOs: Yes
Is Modded: Definitely; Client brand changed to 'fabric'
Type: Client (map_client.txt)
CPU: <unknown>
最佳答案
您将丢弃真正的Settings
,而是通过null
!更改此:
public FabricItem(Settings settings, Settings item$Settings_1) {
super(item$Settings_1);
}
对此:
public FabricItem(Settings settings, Settings item$Settings_1) {
super(settings);
}
您现在还可以从该定义以及在
MyFirstMod
中的调用位置都摆脱掉第二个参数,因为您没有将其用于任何用途。关于java - 结构的Minecraft编码错误:加载“myfirstmod”提供的入口点“main”的条目时发生异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61465581/