Area of blocks by 2 vertices/extending

Discussion in 'Plugin Development' started by william9518, Jan 21, 2013.

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

    william9518

    so my plugin i will stand and do the command, I want to get 2 corners each 3 blocks diagonal away from where I'm standing in opposite directions, making a 10x10 square. I think I know how to do this, but I need to get all the blocks and save them without having to save all the xyzs. Is there a way to only save those 2 corner blocks and then calculating out all of the blocks inside?
     
  2. Offline

    bryce325

    Yes save the values of the corners.
    Then run a method that calculates whatever for all the blocks within those parameters.
     
  3. Offline

    fireblast709

    saving would probably just creating an instance variable (or local if you only need it in the same method) and using for-loops to iterate over the contents
     
  4. Offline

    william9518

    Hmm.. Seems a bit complicated. Can u show me an example?
     
  5. Offline

    fireblast709

    Code:
    Location loc;
    in the class body. For iterating, take 2 arbitrary points:
    Code:
    public void loop(Location p1, Location p2)
    {
        int xmin = Math.min(p1.getBlockX(), p2.getBlockX());
        int xmax = Math.max(p1.getBlockX(), p2.getBlockX());
        int ymin = Math.min(p1.getBlockY(), p2.getBlockY());
        int ymax = Math.max(p1.getBlockY(), p2.getBlockY());
        int zmin = Math.min(p1.getBlockZ(), p2.getBlockZ());
        int zmax = Math.max(p1.getBlockZ(), p2.getBlockZ());
        
        World w = p1.getWorld();
     
        for(int x = xmin; x <= xmax; x++)
        {
            for(int y = ymin; y <= ymax; y++)
            {
                for(int z = zmin; z <= zmax; z++)
                {
                    Block b = w.getBlockAt(x,y,z);
                    // Do stuff
                }
            }
        }
    }
     
  6. Offline

    william9518

    OOOOH im not good with math can u tell me what they mean?
     
  7. Offline

    fireblast709

    william9518 Math.min() just returns the lowest of both values and Math.max() the highest :3. So basically, I get the min and max of x, y and z. Then I just loop over them.

    For instance p1 is (0,0,0) and p2 is (10,10,10).
    • First I check which x is the min and max by using Math.min() and Math.max(). This gives that the cuboid starts at x = 0 and goes on till x = 10
    • the same with y and z
    • the rest is a for-loop (which you should know if you know basic Java). You loop from 0 (the min value) to 10 (the max value)
     
  8. Offline

    william9518

    k thx
     
  9. Offline

    bmcc1234

    i am making something almost identical to this can you tell me how to do that code and where to do it
     
  10. Offline

    william9518

    public void loop(Location p1, Location p2)
    {
    int xmin = Math.min(p1.getBlockX(), p2.getBlockX());
    int xmax = Math.max(p1.getBlockX(), p2.getBlockX());
    int ymin = Math.min(p1.getBlockY(), p2.getBlockY());
    int ymax = Math.max(p1.getBlockY(), p2.getBlockY());
    int zmin = Math.min(p1.getBlockZ(), p2.getBlockZ());
    int zmax = Math.max(p1.getBlockZ(), p2.getBlockZ());

    World w = p1.getWorld();

    for(int x = xmin; x <= xmax; x++)
    {
    for(int y = ymin; y <= ymax; y++)
    {
    for(int z = zmin; z <= zmax; z++)
    {
    Block b = w.getBlockAt(x,y,z);
    // Do stuff
    }
    }
    }
    }
     
  11. Offline

    bmcc1234

    thx i have done this and i get an error here it is help please

    [SEVERE] Could not load 'plugins/RealmsMessage.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.v1_4_6.CraftServer.loadPlugins(CraftServer.java:239)
    at org.bukkit.craftbukkit.v1_4_6.CraftServer.<init>(CraftServer.java:217)
    at net.minecraft.server.v1_4_6.PlayerList.<init>(PlayerList.java:52)
    at net.minecraft.server.v1_4_6.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_4_6.DedicatedServer.init(DedicatedServer.java:104)
    at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:399)
    at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
    at ca.shaw.mrc1.RealmsMessage.RealmsMessage.<init>(RealmsMessage.java:54)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178)
    ... 9 more
     
  12. Offline

    william9518

    at line 54 of your code, there is a NullPointerException.
     
  13. Offline

    bmcc1234

    will there is no error on that line though
     
  14. Offline

    skore87

    There is at runtime.... Whatever you're accessing is null.
     
Thread Status:
Not open for further replies.

Share This Page