Jump to content

How do I get Block inctance and block state value from BlockEntity or BlockState object?


ga1kokuj1n

Recommended Posts

Why aren't you just overriding Item.useOn() in your item? e.g. see DebugStickItem.useOn()

The answer to your direct question is pretty trivial

@Mod.EventBusSubscriber(modid = MODID)
public class ModEvents {

    @SubscribeEvent
    public static void rightClickBlock(RightClickBlock event) {
        if (event.getItemStack().is(MY_ITEM.get())) {
            BlockState state = event.getLevel().getBlockState(event.getPos());
            Block block = state.getBlock();
            // etc.
        }
    }
}

 

Edited by warjort
  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Thank you, warjort!

32 minutes ago, warjort said:

Why aren't you just overriding Item.useOn() in your item? e.g. see DebugStickItem.useOn()

Sorry? I'm not a profetional programmer and also I started modding just a few days ago, so I don't know every features of this framework now, and I even didn't know that there is such a method in Item class I can override.

 

By the way, does exist a full documentation for forge instead of docs.minecraftforge.net, that describes every classes, methods etc. No doubt it's a useful documentation to introduce you to the basics of working with the system, but in my opinion it is not enough, and I would like to have some full-complete documentation instead of trying at random, reading library packages for many hours and bombarding the forum with questions about every little thing.

Link to comment
Share on other sites

Minecraft is not documented. It is closed source software.

Common modding tasks are documentated on the wiki: https://forge.gemwire.uk/wiki/Main_Page

But don't expect to it to have everything. It mostly concentrates on the parts where you need to do things differently to what vanilla does.

If it is not documented on the wiki, you should look at how something similar in the vanilla codebase works. Or find another mod doing a similar thing to learn from.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.