Error getting project using forge method

`public static final CommandSpec SPEC = CommandSpec.builder()
.executor(new LiBao())
.arguments(GenericArguments.optional(GenericArguments.string(Text.of(“reload”))))
.description(Text.of(“reload”))
.build();

@Override
public CommandResult execute(CommandSource send, CommandContext args)
		throws CommandException {
	if (send instanceof Player)
	{
		Player player = (Player)send;
		Item item = Item.getByNameOrId("minecraft:stone");
		//player.openInventory(GuiLiBao.getLiBaoInv(player));
	}
	return CommandResult.success();
}`

Why are errors reported here?Item item = Item.getByNameOrId("minecraft:stone");

Could you describe the issue you have? Not sure what you mean by “error getting project using forge method”

As for Item, item is the Entity Item (also know “dropped item”) and does not contain any static method of getByNameOrId(String).


I called forge’s get item method in the command class of sponge, and there was an error.
The error is explicitly indicated by the code in the red box.
But sponge didn’t tell me more about it

Do you have the error. Maybe more useful to know whats going on

Your error is MCP isnt being applied to your plugin.

How are you building your plugin? Via “extract jar”?

Using eclipse to export directly

Thats where your issue is, MCP makes development easier by renaming everything in minecraft to human readable names, however MCP can not convert it on the fly, therefore when you extract your jar MCP needs to be applied to it.

If you build your plugin through gradle then MCP will be applied. Assuming your using ForgeGradle to gain minecraft in your development enviroment, you should build your plugin using the following command.

gradle clean build

You can find the document for Sponge with ForgeGradle here

https://docs.spongepowered.org/stable/en-GB/plugin/internals/mcp-setup.html

I see. Thank you very much

I have a question, why can I export to jar before?
And there will be no errors.

Did you have any minecraft/forge code at that point in time? Or was it just sponge?


This is a plug-in developed by other authors.
After getting the source code, you can export it directly without any problems

If the code of where those two imports are used is not ran then it would still work. Other then that then it wouldn’t

The author invokes these two references in this class method.

I can see that the imports were used. Im saying if those methods arnt ran when you were testing it, then no error would have been thrown as the code hasnt ran

All of these methods have been used.
It is also used at runtime.

But he won’t have any problems

Is it because I call the ItemStackUtil class.
Does he call the EntityPlayer class?

Any and all classes from minecraft (as in net.minecraft) will cause a crash if not converted. So EntityMP will still cause the crash.

I personally dont know why it doesnt crash with that code if those methods are ran during runtime as by all accounts it should unless there is emulation going on