Modding Help how to merge the oredistributions file for a ore mod? ~Solved~

Discussion in 'Starbound Modding' started by Delta Junkies Gaming, Jan 1, 2015.

  1. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    hello i have made a ore mod but how do i get to merge the oredistributions.configfunctions file




    i really need help fast with this because i am going to use that ore to make a weapon mod pack with all made by ME
     
  2. Olxinos

    Olxinos Scruffy Nerf-Herder

    Best Answer
    No, but you got the idea.
    it would be right if you wanted to patch this file:
    Code:
    {
      "surfaceores" :{ "coalore":1.40 }
    }
    
    but the original file is:
    Code:
    {
      "surfaceOres" : [
        [0.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
        [1.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
        [2.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
        [3.5, [ [ "coal", 1.40], [ "uranium", 0.50], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
        [4.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ],
        [5.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.20], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ]
    
      ]
    ...
    }
    
    The thing is that the structure of that particular file is a bit weird: there are up to 4 nested arrays which makes it hard to replace a specific inner element.
    in, fact, if you want to replace the value correspond to the first coal, it should be:
    Code:
    [
      {
        "op": "replace",
        "path": "/surfaceOres/0/1/0/1",
        "value": 1.05
      }
    ]
    which means: replace the second element of the first element of the first element of the first element of the array "surfaceOres" (the first element of an array is indexed with 0 not 1)
    The thing is, here, you assume that that specific element refers to the coal ore.
    Normally, you could ensure you don't do anything wrong, by testing it before with
    Code:
    [
      {
        "op": "test",
        "path": "/surfaceOres/0/1/0/0",
        "value": "coal"
      }
    ]
    and cancel the whole patch if you aren't modifying the coal ore probability... but it is still buggy and if the condition isn't met, the game will crash


    another solution, is to replace the whole array (of arrays of arrays of arrays) with something like:
    Code:
    [
      {
        "op": "replace",
        "path": "/surfaceOres",
        "value": [
          [0.5, [ [ "coal", 1.05], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
          [1.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
          [2.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
          [3.5, [ [ "coal", 1.40], [ "uranium", 0.50], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
          [4.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ],
          [5.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.20], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ]
        ]
      }
    ]
    there are two problems with that though:
    - it will probably cancel the changes of other mods which modify that object (for instance, if the mod adds new ores)
    - it is very verbose (and especially very redundant with the vanilla files if you make only a few changes)
    still, if you want to change several values at once and you don't care about mod compatibility, it's totally valid

    Edit: oops two errors in my patches: it's 0/1/0/x and not 0/0/0/x (that's the problem with the first solution: it isn't really intuitive and very error prone), also it's 1.05 and not "1.05"
     
    Last edited: Jan 1, 2015
    Claith and The | Suit like this.
  3. C0bra5

    C0bra5 Oxygen Tank

    use the current patching system, simply create a new file in the same directory as the file you want to merge to(since we don't use the merge_ function i believe that "patch" would be a better word in this case) and rename it so that it ends by .patch instead of it's normal extention.
    eg:
    original file: yolo.something
    patch file: yolo.something.patch​

    then you create the patch you need. if you don't know the patching system yet, here is a link to a great tutorial made by xxswaterlitexx : http://community.playstarbound.com/index.php?threads/basic-patching.84496/
     
  4. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    i have read that but how would i replace the code in oredistribution.configfunctions

    i know its something like this
    [ {"op":"replace","path":"????","value":{"item":"????"} } ]
    what do i put as the path and item because it isnt a item i am replacing it is a bit of code
     
  5. C0bra5

    C0bra5 Oxygen Tank

    let's create an example!
    here is a fictive file where you would want to replace something inside of it:
    Code:
    {
        "foo" : {
            "bar" : "str",
            "boo" : "str2"
        }
    }
    let's say we want to replace the boo value for an other one, let's say that we want to replace "str2" by "str3".

    as you know the patching system uses 3 things:
    1) an operator
    2) a path
    3) a value​

    the first element is quite easy to find, in our case we want to replace a value by an other,
    therefor the value given to the operator is "replace"

    the second element is a bit tricky,
    the path is not the path were the file is stored like one could think, but it is the path in the file,
    a good way to think of it is to replace all the "{" by a "/", to remove all the ":", quotation marks, non related elements and the "}" of the picture and to remove all the associated values of the elements..
    let me show you, i but in red all the text that will be removed, put in yellow the text what will be removed and put in green the text that will be kept :
    {
    "foo" : {
    "bar" : "str",
    "
    boo" : "str2"
    }
    }

    when i put all the tansformed and remaning text together i obtain this:
    Code:
    /foo/boo
    and guess what this is just what you needed!
    this is the value for the path.

    now the 3nd element is quite easy to find since you decided what you wanted to do set it to when you started creating the patch code.
    there fore since we want to replace "str2" by "str3" we will simple set the value of "str3" to the value element.
    now we have all our values!

    and the patch for the code would look like this:
    Code:
    [
      {
        "op": "replace",
        "path": "/foo/boo",
        "value": "str3"
      }
    ]
    NOTE: you can also use some diff generators if you need know what the file would look like once the file is patched.
    kawa has made a JSON lab where you will find a ton of tool including a diff generator and a tool to test your patches.

    if you have the the patched code just put it in the patch text area and put the original one in the source code one and then just click diff to get your patch all written down for you.
     
  6. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    Code:
    [
      {
        "op": "replace",
        "path": "/surfaceores/coalore",
        "value": "1.05"
      }
    ]
    would this be correct?[DOUBLEPOST=1420147503][/DOUBLEPOST]??
     
  7. C0bra5

    C0bra5 Oxygen Tank

    http://helmet.kafuka.org/sbmods/json/ try it for your self!
    but that might be wrong since most numbers don't need quotation marks around them when you write them down in the files.
     
  8. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    can you just give me the code for it i just want to make my modpack
    ...[DOUBLEPOST=1420149284][/DOUBLEPOST]and i am going offline soon because my laptop is flat :rofl:
     
  9. Olxinos

    Olxinos Scruffy Nerf-Herder

    Best Answer
    No, but you got the idea.
    it would be right if you wanted to patch this file:
    Code:
    {
      "surfaceores" :{ "coalore":1.40 }
    }
    
    but the original file is:
    Code:
    {
      "surfaceOres" : [
        [0.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
        [1.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
        [2.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
        [3.5, [ [ "coal", 1.40], [ "uranium", 0.50], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
        [4.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ],
        [5.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.20], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ]
    
      ]
    ...
    }
    
    The thing is that the structure of that particular file is a bit weird: there are up to 4 nested arrays which makes it hard to replace a specific inner element.
    in, fact, if you want to replace the value correspond to the first coal, it should be:
    Code:
    [
      {
        "op": "replace",
        "path": "/surfaceOres/0/1/0/1",
        "value": 1.05
      }
    ]
    which means: replace the second element of the first element of the first element of the first element of the array "surfaceOres" (the first element of an array is indexed with 0 not 1)
    The thing is, here, you assume that that specific element refers to the coal ore.
    Normally, you could ensure you don't do anything wrong, by testing it before with
    Code:
    [
      {
        "op": "test",
        "path": "/surfaceOres/0/1/0/0",
        "value": "coal"
      }
    ]
    and cancel the whole patch if you aren't modifying the coal ore probability... but it is still buggy and if the condition isn't met, the game will crash


    another solution, is to replace the whole array (of arrays of arrays of arrays) with something like:
    Code:
    [
      {
        "op": "replace",
        "path": "/surfaceOres",
        "value": [
          [0.5, [ [ "coal", 1.05], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
          [1.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "iron", 0.20] ] ],
          [2.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
          [3.5, [ [ "coal", 1.40], [ "uranium", 0.50], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "titanium", 0.20] ] ],
          [4.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.00], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ],
          [5.5, [ [ "coal", 1.40], [ "uranium", 0.00], [ "plutonium", 0.00], [ "solarium", 0.20], [ "copper", 0.20], [ "silverore", 0.20], [ "gold", 0.20], [ "platinum", 0.20], [ "diamond", 0.20], [ "aegisalt", 0.20], [ "rubium", 0.20], [ "violium", 0.20] ] ]
        ]
      }
    ]
    there are two problems with that though:
    - it will probably cancel the changes of other mods which modify that object (for instance, if the mod adds new ores)
    - it is very verbose (and especially very redundant with the vanilla files if you make only a few changes)
    still, if you want to change several values at once and you don't care about mod compatibility, it's totally valid

    Edit: oops two errors in my patches: it's 0/1/0/x and not 0/0/0/x (that's the problem with the first solution: it isn't really intuitive and very error prone), also it's 1.05 and not "1.05"
     
    Last edited: Jan 1, 2015
    Claith and The | Suit like this.
  10. C0bra5

    C0bra5 Oxygen Tank

    if you want to make a thing you need to know how to make the thing
     
    Last edited: Jan 2, 2015
  11. SleepySquidd

    SleepySquidd Tragically Magic Hands

    Delta, I understand that you're not quite grasping this concept but you need to understand other people wont give you the code because we have our own projects/busy lives that need attention. We'd be happy to help but we won't make your mod for you
     
    Boshed and The | Suit like this.
  12. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    I am sure what Olxinos posted will now be engough for me thanks for all the help anyway
     
  13. Claith

    Claith Big Damn Hero

    Thanks for this. I need to revisit a mod that works with this stuff again, and I really didn't want to fuss with it, so you saved me a half hour or so.
     
    Delta Junkies Gaming likes this.
  14. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    btw i am still stuck on my mod but i will find a way around it[DOUBLEPOST=1420343366][/DOUBLEPOST]
    i know what you said but would anyone be able to fix my mod up
    this will help me a lot because i still have the rest of the mods to make to go with it
    plus anyone that wants to help can help if they would like to just pm me for info about it
    ~
     
  15. C0bra5

    C0bra5 Oxygen Tank

    i'm also working on my own modpack, and i ask for help about problems i have while coding,(eg: new update that i'm not aware of changes something that i din't knew, problems that i cant identify, etc), )not for people to do my job.
     
    SleepySquidd likes this.
  16. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    ? 1 i am asking if someone could help me fix it up so it will work and 2 i said anyone can help if they wanted to
     
  17. The | Suit

    The | Suit Agent S. Forum Moderator

    The biggest question you honestly need to ask your self.
    How are you planning on fixing your "other mods" if you still haven't figured out how to fix this?

    Olixnos spent time writing up a great example of what to do.
    Now its time to take your part to learn how to apply that knowledge.
     
  18. Delta Junkies Gaming

    Delta Junkies Gaming Intergalactic Tourist

    One i never said i am fixing my other mods up i said i was making them
    as in one at a time get them running then add them to a single folder and add the ore.

    and about the new patching system do i have to have say oredistributions.configfunctions or just have the oredistributions.configfunctions.patch ?
     
  19. The | Suit

    The | Suit Agent S. Forum Moderator

    If you use the patch system - it must include.patch at end of it.
    Have you made a mod before?

    If not it is a good idea to follow these 2 guides
    Follow the tutorial from start to finish. Till the mod works.
    http://community.playstarbound.com/index.php?threads/modding-basics-p1-editing-vanilla-files.86970/

    Read the patch guide completely
    http://community.playstarbound.com/index.php?threads/basic-patching-now-with-path-guide-v1-3.84496/

    To be honest there is no point in thinking about making a "mod pack" if these 2 basic things are not solid.
     
    Dunto likes this.

Share This Page