[solved]Still dont understand how to program a cuboid.

Discussion in 'Plugin Development' started by TopGear93, May 9, 2012.

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

    TopGear93

    Ive been trying to learn how cuboids work so i can implement them into a huge project im working on. I cant seem to get the idea of how they work and how id even code them.

    What im looking to do is create an invisible square that will only allow a select player to interact within it. If the player is not the owner of this square it will cancel breaking,placing, and interacting with blocks/materials.

    Yes i know theres a few plugins that use them and ive been offered to look at them in the past. Those plugins dont help me. Id like a full tutorial to creating custom sized cuboids.
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    The first obvious question that needs to be asked is do you know what a cuboid is (in terms of geometry and how it relates to minecraft)? And how they can be defined geometrically?
     
  3. Offline

    TopGear93

    A cuboid could be a square,circle,rectangle, etc using the blocks within minecraft. To create a square select one lower block and select another higher block in the relative corner.

    Get the first lower block and count how many blocks to the next higher block.

    The side view below shows that it would be 9 blocks back/forward and 4 blocks up or down.

    Example:
    B = block
    S = Selected block

    TopView
    SBBBBBBBBB
    BBBBBBBBBB
    BBBBBBBBBB
    BBBBBBBBBB
    BBBBBBBBBS

    Side View:
    BBBBBBBBBS
    BBBBBBBBBB
    BBBBBBBBBB
    BBBBBBBBBB
    SBBBBBBBBB
     
  4. Offline

    desht

    No, a cuboid will never be a circle or anything other than a geometric cuboid. It will have six faces, and they will all be rectangular (or square, but then a square is just a type of rectangle anyway).

    By far the easiest way of representing a cuboid is to store two co-ordinates (x1, y1, z1) and (x2, y2, z2), where x1 <= x2, y1 <= y2, z1 <= z2. Those two co-ordinates represent opposite corners of the cuboid - in Minecraft terms, the lower northest and upper southwest corners. Your cuboid class could have a constructor taking two Location objects, or maybe just six integers representing the co-ordinates. Your constructor should ensure that the "upper" and "lower" co-ordinate pairs get allocated correctly (Math.min and Math.max are your friends here). A Bukkit Cuboid class should also include an instance of the World it's in (or perhaps just the world name to weaken the reference).

    Once you have that, it becomes quite easy to define a bunch of operations (i.e. methods) on your cuboid. E.g. a boolean contains(Location loc) method which simply checks if loc.getBlockX() >= x1 && loc.getBlockX() <= x2, and similarly for Y and Z. Oh, and loc.getWorld() had better match the cuboid's world too...

    I've written a fairly extensive Cuboid class here: https://github.com/desht/ChessCraft.../java/me/desht/chesscraft/regions/Cuboid.java - you are welcome to browse the code, use ideas from it, etc. But be aware that if you want to use the class or any part of it directly, that it's licensed under the GNU GPL, and any work that uses it must also be licensed thus.
     
    TopGear93 likes this.
  5. Offline

    TopGear93

    Ah math, my greatest enemy. It's gonna take a while to understand this. I did take a look at your class and it seems the setup is basically straight forward. Thanks for the help.
     
Thread Status:
Not open for further replies.

Share This Page