Jump to content

Recommended Posts

Posted (edited)

So for this metal detector item I'm making I need a key-value pair structure officially supported by Mojang in a json file. I have been recommended tags but those simply just don't fit for my needs. The problem I'm having is that the official tags are very limited, see below.

I want the player to be able to choose which type of ore they want to detect rather than to just detect all ores and point to the closest ore. You could also implement a "valuabilityscore" system or something like that but tags still wouldn't work for that.

Here's the structure I have to work with:

{
  "replace": false,
  "values": [
    {
      "id": "minecraft:iron_ore",
      "findingDistanceMultiplier": 1,
      "values": [
        "#minecraft:iron_ores"
      ]
    },
    {
      "id": "minecraft:gold_ore",
      "findingDistanceMultiplier": 0.5,
      "values": [
        "#minecraft:gold_ores"
      ]
    },
    {
      "id": "minecraft:copper_ore",
      "findingDistanceMultiplier": 1.5,
      "values": [
        "#minecraft:copper_ores"
      ]
    },
    {
      "id": "minecraft:ancient_debris",
      "findingDistanceMultiplier": 0.2,
      "values": [
        "minecraft:ancient_debris"
      ]
    }
  ]
}

I don't know if it's a good idea to every time loop through these to find the value field. It just feels hacky and it's frustrating to implement.

Here's the structure I want to work with:

{
  "replace": false,
  "values": [
    "minecraft:iron_ore": {
      "findingDistanceMultiplier": 1,
      "values": [
        "#minecraft:iron_ores"
      ]
    },
    "minecraft:gold_ore": {
      "findingDistanceMultiplier": 0.5,
      "values": [
        "#minecraft:gold_ores"
      ]
    },
    "minecraft:copper_ore": {
      "findingDistanceMultiplier": 1.5,
      "values": [
        "#minecraft:copper_ores"
      ]
    },
    "minecraft:ancient_debris": {
      "findingDistanceMultiplier": 0.2,
      "values": [
        "minecraft:ancient_debris"
      ]
    }
  ]
}

Is it possible to implement the latter in one way or the other in vanilla Minecraft? If so, how would I even use it? It would be nice to have that mod compatibility. But I could also use the former data structure if I can figure out how to loop through the Json file and find the value field i'm looking for. If you have answers to any of these question please do respond

Edited by hasanchik
Posted

Tags, don't have that structure. They are an isA relation.

They let you do a blockState.is(TagKey) check to see if a block is part of the tag and that's it.

 

You can write your own datapack type with whatever structure you like.

See minecraft's PreparableReloadListener and its subclasses, you can register your own using the AddReloadListenerEvent

that's how forge's internal mod loads dynamic loot modifiers:

https://github.com/MinecraftForge/MinecraftForge/blob/2815e69407fe64523b6f4165a9fd965333634afd/src/main/java/net/minecraftforge/common/ForgeInternalHandler.java#L120

https://github.com/MinecraftForge/MinecraftForge/blob/1.19.x/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java

 

Or you can just use a config file:

https://forge.gemwire.uk/wiki/Configs

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

Posted

Sorry for the late reply, but how do I make one of these custom datapack types? Looking at the PreparableReloadListener class and its subclasses hasn't helped me much. 

And when I do have set up one of these classes, how do I get values from it like described in my post? 

Posted

1) Use the event to register your listener

2) During the prepare stage of the listener, parse the json files

3) During the accept stage populate your data structure(s) from the previously parsed json data

The subclasses of PreparableReloadListener provide many "frameworks" for common use cases.

 

I already linked a forge example,

or you can look at one of the many vanilla examples (recipes, loot tables, etc.)

or the similar processing of assets from resource packs (models, textures, etc.)

or you can search github for other mods doing something like what you are trying to do, e.g. https://github.com/search?l=Java&q=SimpleJsonResourceReloadListener&type=Code

 

Beyond that, your question lies outside the scope of this forum.

Feel free to ask more specifics questions where you have at least tried to implement something, rather than "tell me how to write my mod for me" type questions.

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

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.