[Unsolved] How to get Sand in a World and then clear it..

Discussion in 'Plugin Development' started by ASHninja1997, Jul 28, 2013.

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

    ASHninja1997

    I am wondering how to get all the send in a World then replace it with air.
    Any one know how to do this?
     
    etaxi341 likes this.
  2. Offline

    Tzeentchful

    If it's a new world you could create a custom terrain generator.
    You can find more details on world generators in the resource section.

    If it's an existing world then there is no easy way to do it without creating alot of lag.
    The best way to do it would be to lissen for the ChunkLoad event then loop through the chunk and sent any sand to air.
     
  3. Offline

    ASHninja1997

    Tzeentchful
    The Player will be playing in a flat world and at the end of every ten minutes Sand is cleared from the world...so there won't be much sand
    P.S. I am not worried about lag for 3 seconds
     
  4. Offline

    etaxi341

    ASHninja1997 But scaning through the whole generated World will take much more than 3 seconds.
     
  5. Offline

    ASHninja1997

    etaxi341
    Is there any way to do it?
     
  6. Offline

    etaxi341

    ASHninja1997 There are ways to check for every Chuck in a World if it contains this Block and then you need to check the whole chunk for this Block. This causes in Big Worlds about 10 Minute Lag and in newly generated Worlds about 50 seconds. So I don't know any "Good" way to do it.
     
  7. Offline

    ASHninja1997

    etaxi341
    What if all the Sand blocks were on a grass flat world?
    And there where only about 30 of em'.
     
  8. Offline

    etaxi341

    ASHninja1997 You mean that you only need to check one layer? So the Map is about 10 Blocks High and at Block 11 is the Sand? Then you just need to check 11 at the Y-Axis. And how is the Sand spawned? Do the Players place it or is the Server spawning it? If yes you could save the Locations and remove them from these Locations. So you won't get lag by checking the World for Sand.
     
  9. Offline

    ASHninja1997

    etaxi341
    I made a bow that Shoots a object that then spawns Sand where it lands.
    So I need to know how to clear it from the world..I have never messed with this type of stuff before so if you could give me some type of starting point of code, I could take it from there and tell you if I get any error's.
     
  10. Offline

    etaxi341

    So exactly where the object/Arrow lands will be spawned a sand block? Save the Location of the Sand Block in an ArrayList and then whenever you want to remove the sand you get through every entry in the ArrayList and replace this Blocks with Air and remove the Locations from the ArrayList.
     
  11. Offline

    Firefly

    In the same place you execute the code the spawn in the sand, save their locations in, for example, a HashSet. Then, when you want to reset the world, iterate through all your stored locations and set them to air. Quick and dirty, would not work if the sand has fallen (you'd have to get it's final location).

    Edit: Damn ninjas.
     
  12. Offline

    etaxi341

    Firefly To get the final Location you could just check the Location where it has been spawned and from this Location down to 0 at Y-Axis. This causes a bit more lag but I think you nearly can't notice it.
     
  13. Offline

    Firefly


    Yup, just pointing out to him. We don't quite know how he spawns in the sand.
     
  14. Offline

    ASHninja1997

    Firefly
    I removed comment. Didn't know what "ninja" meant :p
    etaxi341
    Here is how I spawn the sand
    Code:
    Entity entity = e.getEntity();
            if(entity instanceof ThrownPotion){
            Location l = entity.getLocation();
            World w = entity.getWorld();
            w.spawnFallingBlock(l, Material.SAND, (byte) 1);
            return;
     
  15. Offline

    xTrollxDudex

    No, he means he got ninja'd, a person posted the answer he was going to say before him.
     
    etaxi341 likes this.
  16. Offline

    ASHninja1997

    xTrollxDudex
    thanks for telling.
    Firefly
    Man I am sorry about that..I miss interpreted the message.
    Now that I know what that means I someday hope I can repay you for my unnecessary comment .
     
    Firefly likes this.
  17. Offline

    etaxi341

    ASHninja1997 OK so now you just need to save the Location "l", how you called it, in an ArrayList.
    Create an ArrayList like this:
    Code:java
    1. public ArrayList<Location> SandLocs = new ArrayList<Location>();

    And add the Location like this:
    Code:java
    1. SandLocs.add(l);
     
  18. Offline

    ASHninja1997

    etaxi341
    Humm....So how would I remove the sand from the locations where it spawned?
    Because when ever I try to get the SandLocs ArrayList it says I can't get the ArrayList if it's a location. In other words it tries to change the location l to String l.
     
  19. Offline

    etaxi341

    ASHninja1997 Something like that:

    Code:java
    1. for (int i = 0; i <= SandLocs.size();i++){
    2. Location l = SandLocs.get(i);
    3. l.getBlock().setType(Material.AIR);
    4. }
     
  20. Offline

    ASHninja1997

    etaxi341
    Thank you for all your help :D. I won't be able to test this out for reasons, but when I do I will tell you if it worked
     
  21. Offline

    Firefly


    Np. Sorry I couldn't help out more, I had to go soon. Hope you got your problem solved :)
     
Thread Status:
Not open for further replies.

Share This Page