Solved Regenerating Terrain

Discussion in 'Plugin Development' started by TheMintyMate, Jun 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    TheMintyMate

    In May, I came across a thread which asked a similar question. In the thread, there was a comment claiming that it could be done : "Block object has BlockState which you store into the List. Then later on, for each BlockState in the list invoke update BlockState method."
    So, does anyone have any suggestions of how do this? Hope this will also help others who want to regen terrain. I have to say, Im out of my way to know how to do this!
     
  2. Offline

    Niknea

    TheMintyMate I would do the following.

    1. Create a new HashMap, this will be used to store the block and the location.

    2. Loop through all the block(s) that were damaged, and get their location(s)

    3. Add each block's location to the HashMap, along with what type of block it is.

    4. Loop through the HashMap and lace the blocks that were stored in the HashMap.
     
    CynutsBR likes this.
  3. Offline

    xTigerRebornx

    Niknea Breaks for anything that stores more data then just the 'type'. All he needs a List of BlockState(s).
    He then needs to add the state of the block he wants to restore to the list (where the state was captured as what he wants to restore it to), then call update() on those states when he wants to restore them.
    TheMintyMate
     
  4. Offline

    TheMintyMate

    Niknea
    Thanks! Did want to check, how would you setup the HashMap? What do I add? eg:
    Code:
    //heres a general HashMap
    Map<String, Location> locations = new HashMap<String, Location>();
    //so...
    Map<//what to put here> block = new HashMap<//what to put here>();
    
    Also, xTigerRebornx, how would I use your method?
     
  5. Offline

    Niknea

    TheMintyMate change map to hashmap, and have the parameters Location, and Material.
     
    TheMintyMate likes this.
  6. Offline

    xTigerRebornx

    Niknea Like I've said before, this doesn't work past anything with data (anything that isn't just material based, like a Log, Chest, Door, Torch). Shouldn't keep suggesting a method that will easily break without the OP adding multiple workarounds for all possible blocks.
    TheMintyMate However you get your blocks, simply grab their state using Block#getState() and store it in a list/set. Then, when you want to restore the saved area, simply loop over that set/list and call BlockState#update() on each BlockState and pass in true to force the updated (you are required to force the update as not forcing it will cause problems when changing type)
     
    TheMintyMate likes this.
  7. Offline

    TheMintyMate

    Niknea
    Thanks :) I guessed it would be something along those lines...
    xTigerRebornx
    Wondered if you could post a code example? Thanks :)
    Im going to put this thread to rest, though I may post how I have done it. I am however interested in what your suggesting xTigerRebornx
    - Minty
     
  8. Offline

    xTigerRebornx

    TheMintyMate Simple concept. When you have a Block, you can invoke getState() on it, giving you a BlockState. This BlockState is a snapshot of the Block, meaning it stores its data that it held at the time of invoking getState(). You can call update() (passing in true to make sure it overrides the block) and it will put the BlockState back in the world, "updating" the Block you called getState() on.
    Now, if you had an area, you could simply loop through, grabbing each of the Block's BlockState and put them in a List or Set. Then, when you want to regenerate, looping through the List/Set and calling update(true) on all of the states would restore the area.
     
Thread Status:
Not open for further replies.

Share This Page