Manipulation of a Large Group of Armor Stands

Discussion in 'Spigot Plugin Development' started by Kyrix, Sep 16, 2018.

  1. Hey there!
    So, I haven't tried anything yet, but how would I be able to to have 40 armor stands stacked next to each other on the ground in a 4x10 block formation for example, and have each armor centered in the center of the block. How would I make so it would follow the player, while staying in the 4x10 formation.

    How would I cache the armorstands, should I stick them into an 2 dim array, or just an array? How would I spawn each armorstand in their correct place (without repetition)? How would I deal with tracking player's movement and keeping armorstands in sync with the player and their locations?

    I've never used the player move event, not sure if it would be an efficient way to deal with changing location of armorstands.

    Here's a diagram: https://prnt.sc/kv1793

    I am not looking for solid code, I just want something to help me with the logic (and math?) behind working this out.

    Thanks guys!
     
  2. Player move event fires thousands of times per second with just a tiny wiggle of the mouse. So you need to be really careful how you implement code inside it especially things that read/write from disk or expensive calculations that take a long time.

    *IF* you decide to use onPlayerMove I would suggest taking advantage of the event.getFrom() event.getTo() methods.

    Compare the xyz values from both of those methods and if they’re not == then the player has moved a full block. That will cut down the executions on onPlayerMove to just once a block which shouldn’t cause you any problems.

    As for moving the object you’ll probably just need to teleport them one at the time to the next location. I assume you’re using some sort of loop to spawn them in originally. If you store them into an array in the order they need to be spawned you should be able to teleport them to the right spots by going through the array in order.


    Sent from my iPhone using Tapatalk
     
  3. 20*
     
    • Agree Agree x 1
  4. I am having problem thinking of a way to spawn the armor stands and place them into a data structure (idk if that's the word but I mean like a collection or array)
     
  5. The way I’ve seen it done in the past is the name of the armor stand represents its xyz location in the world it’s “id” and maybe it’s rotation? I suppose rotation might not be needed once spawned though.

    You might want to look at furniturelib, it does this and the API is pretty good, the author is active as well and quite helpful.


    Sent from my iPhone using Tapatalk
     
  6. Maybe iterate through it changing the x/y/z until you have it where you like it? Then you just need to save a corner/center and use that to place the rest of it.
     
  7. I don't think that would be the way because the coords of the location will be unknown to me in the code.
     
  8. Well if you don’t know the location... you can’t spawn it in. You’ll obviously know the location of the player who it’s following and have to set your cube up relative to that. Entities can also have NBT data that you can set and remove.


    Sent from my iPhone using Tapatalk
     
  9. Yes, the locations of the entities are relative to the player's location. Now, how would I spawn them in order, and in their formation. Also, would it be necessary to cache the entities in memory using a collection or a multi dimensional array (never used one before), if so, how can I store the armor stands in their correct position in one?
     
  10. I mean I feel like get the first location and do some math to generate the minX Y Z/Maxx YZ then loop through from min to max on the x y z and spawn a stand there.

    Yeah you need to save them to an object in some order that makes manipulating them easier.

    If there’s a set distance between them that is say 0.5 blocks you could just add the difference between the first relative location and second when you teleport each one you read back in from the storage object. Don’t know that a 2d array is useful since you need 3d positioning. And they’re typically more of a pain to work with. I’d create a “cube” object that stored all of the stands for the cube and its relative position, as well as the spawn / teleport methods


    Sent from my iPhone using Tapatalk
     
  11. minimal overhead would be a 2d array mapped to a 1d array (Google on how to do that), then you can extact the x and y index and multiply them with your dimensions.
     
  12. as I lack better naming:
    • Shape class, which stores an origin (the location the shape is rendered at) and a list of Parts (not even bothering with more dimensions)
    • Part class, which stores an ArmorStand and a Vector relative to the origin stored in Shape)
      • instead of storing a raw ArmorStand, you could opt to store the UUID and a WeakReference<ArmorStand>, to prevent memory leaks. The UUID would allow you to remove the ArmorStand when loaded again, even when the WeakReference is nulled.
     

Share This Page