Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[SOLVED] [1.19.4] A better way to store hashmaps for mod compatibility

Featured Replies

Posted

I need a way to store this type of hashmap somewhere that is supported by vanilla Minecraft in a json file:

protected static HashMap<String, String[]> detectableBlocks = new HashMap<>();

I want to do this for mod compatibility and ease of use. For example if another mod wants to integrate into mine that is supported

What i'm trying to do here basically is have a "type" of block that is detectable. For example you have '"iron_ore": ["deepslate_iron_ore", "iron_ore"], "diamond_ore": ["deepslate_diamond_ore", "diamond_ore"]' ect.

I have looked at "data/minecraft/tags" but it's not clear to me how they are used and why I should use them. The Forge documentations have no simple explanations for these sorts of stuff, so it's hard for me to understand. But that doesn't matter since the value field in a tag json file is an array and not a hashmap anyway.

Is there an equivalent of what I described above in the data folder? Or do I have to make my own custom folder?

Edited by hasanchik

Tags will be your goto for mod compatiblity. Of course the other mods must know about your tag and should add values to them.

What you need to do is to create your custom tag using the Forge documentation
https://docs.minecraftforge.net/en/1.19.2/resources/server/tags/

Then, when you need to check for a block (I'm assuming you want to see if a block falls inside a list of detectable blocks) you need to use the BlockState#is method.

For example, let's say you create your tag "mymodid:detectable_blocks" and inside it you have specified the iron_ores or the diamond_ores (by the way you can also reference other tags in it, so if you reference the #forge:ores/iron tag you'll match also modded iron ores).
When you want to check if a block is part of that tag you need to use the following statementย 
ย 

blockstate.is(MyTags.DETECTABLE_BLOCKS)

Assuming that somehwer in your code you have a class called MyTags and inside that class you have your tag defined as DETECTABLE_BLOCKS.ย 

Tags might look complicated but in reality they are really easy to use and deal with and of course are the recommended approach to maximimze mod compatibility

Don't blame me if i always ask for your help. I just want to learn to be better :)

  • hasanchik changed the title to [SOLVED] [1.19.4] A better way to store hashmaps for mod compatibility

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.