Development Assistance Schematic Iterating

Discussion in 'Plugin Help/Development/Requests' started by terturl890, Jul 1, 2015.

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

    terturl890

    I have done searches on the internet to try to look for a person that has successfully iterate through every block in a schematic by WorldEdit. I plan on getting every block in the schematic and do a slow paste that every second it will paste a certain amount of blocks. I do know how to iterate through Iterates but I just dont know how I would put blocks into the iterater to use the .next() method to paste blocks at certain locations. Can anyone help?
     
  2. Offline

    Scorpionvssub

    Like what cubecraft has? for their house building system
     
  3. Offline

    terturl890

    Yes

    Im thinking that will have to be something dealing with putting blocks into an iterator. The only way I can think of doing this is have the Building pre-built and just copy blocks from that build to paste to other parts of the map. But I want it to be able to pull blocks from schematics.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. Offline

    Ruptur

    @terturl890
    Sometimes all it takes is: http://bfy.tw/c9c

    Example:
    Here is an example demonstrating both Iterator and ListIterator. It uses an ArrayList object, but the general principles apply to any type of collection.

    Of course, ListIterator is available only to those collections that implement the List interface.
    Code:
    import java.util.*;
    
    public class IteratorDemo {
    
       public static void main(String args[]) {
          // Create an array list
          ArrayList al = new ArrayList();
          // add elements to the array list
          al.add("C");
          al.add("A");
          al.add("E");
          al.add("B");
          al.add("D");
          al.add("F");
    
          // Use iterator to display contents of al
          System.out.print("Original contents of al: ");
          Iterator itr = al.iterator();
          while(itr.hasNext()) {
             Object element = itr.next();
             System.out.print(element + " ");
          }
          System.out.println();
        
         // Modify objects being iterated
          ListIterator litr = al.listIterator();
          while(litr.hasNext()) {
             Object element = litr.next();
             litr.set(element + "+");
          }
          System.out.print("Modified contents of al: ");
          itr = al.iterator();
          while(itr.hasNext()) {
             Object element = itr.next();
             System.out.print(element + " ");
          }
          System.out.println();
    
          // Now, display the list backwards
          System.out.print("Modified list backwards: ");
          while(litr.hasPrevious()) {
             Object element = litr.previous();
             System.out.print(element + " ");
           }
           System.out.println();
        }
    }
    
    References: http://www.tutorialspoint.com/java/java_using_iterator.htm
     
  5. Offline

    terturl890

    @Ruptur, that I can do. The problem is putting the blocks from the Schematic into the arraylist.

    Also, a for loop can easily do what that tutorial is showing...
     
  6. Offline

    Ruptur

    @terturl890
    What problem do you have with putting the blocks into an arraylist?
    Quite simply list.add(#) ?
     
  7. Offline

    terturl890

    You cant just get the blocks in the schematic. You have to iterate through the blocks in the schematic. That is my trouble.
    @Ruptur
     
  8. Offline

    nlthijs48

    @terturl890 After you have loaded the schematic on a clipboard, then you can get the blocks from it. I guess you already have the loading part, but this code from my plugin AreaShop might still be useful for that: Schematic loading (GitHub). After you have the schematic loaded on a clipboard you can get its dimensions by using Clipboard#getDimensions(), which returns a Vector with the x, y and z dimension respectively. Then within the bounds of the previously mentioned dimensions you can get blocks with Clipboard#getBlock(Vector position).

    So if you want all the blocks in a list, then you would need 3 loops, one for each dimension, and let those go from 0 until the dimension from the clipboard. And then inside the innermost loop you can use the 3 dimension numbers to get the correct block and add it to the list.

    I'm assuming you are working with WorldEdit 6 here, if that is not the case then let me know (also got code for WorldEdit 5 in AreaShop, it supports both).

    Edit: Changed mention of WorldGuard to WorldEdit as pointed out by terturl890.
     
    Last edited: Jul 2, 2015
  9. Offline

    Ruptur

    @terturl890
    Sorry this was my fault for not fully understanding
     
  10. Offline

    terturl890

    @Ruptur it's ok. I was vague in the first post.

    @nlthijs48
    I think you meant WorldEdit and I am using WE6 yes.
     
  11. Offline

    nlthijs48

    @terturl890 Yes WorldEdit indeed, had that wrong. Were you able to fix your problem now?
     
  12. Offline

    Scorpionvssub

    always wanted a plugin like this X)
     
  13. Offline

    terturl890

    @nlthijs48 I have actually not tested it out yet, I will do that today.
     
Thread Status:
Not open for further replies.

Share This Page