Searching for a cuboid tutorial

Discussion in 'Plugin Development' started by se1by, Dec 12, 2011.

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

    se1by

    Hey I need a tutorial about cuboid regions for a protection plugin.
    Do you have one or could explain the most important?
     
  2. Offline

    halley

    What part of this topic do you need to know?

    A cuboid is also called an axis-aligned bounding box. To define it, you need to know (1) what world we're talking about, and (2) the X, Y, Z integer coordinates of two opposite corners of the region. Most plugins assume that the two blocks that are specified are INCLUDED in the region. In WorldEdit, you can define these two corners in a variety of ways, but most people conjure up a //wand item, then left-click one block and right-click the opposite block with that item.

    Several plugins use cuboid regions, but it's up to that individual plugin to find out how to USE them. You may want to define a region, select a region, search for a region by name or by position, etc., so there's no unified way of working with them. As far as I know, there's no official API on any of the plugins, but lots of talk about making one. Until then, you have to dig into the guts of that plugin with reflection and hope it's a stable entry point.
     
  3. Offline

    se1by

    I got 2 points (aka 2 locations) and I want to save all blocks between as a region.
    I did it with a few loops before and saved every block inside, but I think that there must be a more efficient way.
    @halley
     
  4. Offline

    CptSausage

    Why would you do that? As halley said, the only thing you need is two different locations. If someone breaks a block just check if he's inside the area.
    Code:
    if (YourBlock1X < PlayerX && PlayerX < YourBlock2X + the same for Z) {
     cancel
    }
    @halley I don't know about the other plugins, but WorldEdit has an API. You can get a player's selection with:
    Code:
    Selection selection = ((WorldEditPlugin) plugin.getServer().getPluginManager().getPlugin("WorldEdit")).getSelection(player);
     
  5. Offline

    se1by

    @CptSausage
    Exactly what I need to do when the region is already set, but I want to have a more efficient way to save the protections once the user made one.
     
  6. Take a look at the source code of my Regios plugin or other cuboid protection.
     
  7. Offline

    CptSausage

    What could be more efficient than saving 6 ints to save a cuboid with a size of thousands of blocks?
    You could make just squares, so you would only need 4 ints. Or even a circle which would only require 3 ints.

    But why would you save every single block?
     
  8. Offline

    se1by

    Ah now I get what you meant :D
    Thx!
    Will try it.

    EDIT:
    But how should I get the right 6 ints if I got more than one protection?
     
  9. Offline

    DrBowe

    @se1by
    Create a Region/Selection/Protection/whathaveyou class that stores these values, and just create new instances of the class when necessary.

    OOP, my friend.
     
    dbizzzle likes this.
  10. Offline

    se1by

    I meant if there are more than one region saved.
    eg
    region1
    from 0.0 , 0.0 , 0.0
    to 10.0 , 10.0 , 10.0

    region2
    from 20.0 , 20.0 , 20.0
    to 30.0 , 30.0 , 30.0

    and someone break a block at 5.0 , 3.0 , 1.0
    How can I check if he is in region1 or region2?
    Checking every protection seems a little bit inefficient.
     
  11. Offline

    halley

    So, you have a number of regions, and you just want to say "what region is block B inside?"

    It's easy to check if block B is inside a region R.

    Code:
    // pseudocode, not actual Java syntax
    if (R.getWorld() == B.getWorld() &&
        R.getMinX() <= B.getX() && B.getX() <= R.getMaxX() &&
        R.getMinY() <= B.getY() && B.getY() <= R.getMaxY() &&
        R.getMinZ() <= B.getZ() && B.getZ() <= R.getMaxZ())
       { return YES block B is inside region R. }
    
    Yes, there are a thousand super-complicated ways that you can avoid checking EVERY region for whether it is inside or not. (Google b-trees, octrees, etc.) However, unless you have something like 2000 regions on a given world, I would not bother trying to implement them. You'll pull your hair out to get them to work without many hours of coding and debugging. The check above is quite quick.
     
  12. Offline

    se1by

    @halley
    thx just thought that there might be a better way
     
  13. Offline

    EarlyLegend

    I know I was never involved in this conversation before, but I just found it and I want to say thanks 'cause you helped me out a lot too ;)
     
Thread Status:
Not open for further replies.

Share This Page