Solved Position relative to location

Discussion in 'Plugin Development' started by Xp10d3, Jun 16, 2022.

  1. Offline

    CraftCreeper6

    Okay probably change that back.

    Would you mind creating a repo so I can take a better look? It's probably something silly :)

    Sent from my LE2123 using Tapatalk
     
  2. Offline

    Xp10d3

    Sure; no problem. What's your Git?
     
  3. Offline

    CraftCreeper6

    Would be better to post it public for others to see but it's Zalosath.

    Sent from my LE2123 using Tapatalk
     
  4. Offline

    Xp10d3

  5. Offline

    CraftCreeper6

    Alright so I've had a good glance and nothing pops out. It's 1am though so it's tomorrow's job :)
    Will check it out tomorrow.

    My best guess right now is with serialization and deserialization as all the vector math adds up. So if you want to continue looking, that's where I'd be looking (with plenty of debug).

    Sent from my LE2123 using Tapatalk
     
    Xp10d3 likes this.
  6. Offline

    Xp10d3

    Okay. Thank you so much for your help! Lemme know when you find something. I'll also do some digging in my spare time
     
  7. Offline

    CraftCreeper6

    @Xp10d3
    Ahah, problem solved.

    Set the map:
    [​IMG]

    Move to new location:
    [​IMG]

    Create the map:
    [​IMG]

    The issue as it turns out was that the Vector maths we were doing was not working the way we intended it to.

    In your getBlocks method:
    Code:
    public ArrayList<Block> getBlocks(Block start, int radius) {
            ArrayList<Block> blocks = new ArrayList<Block>();
            for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) {
                for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) {
                    for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) {
                        Location blockLocation = new Location(start.getWorld(), x, y, z);
                        Location loc = blockLocation.subtract(start.getLocation());
                        Block block = new Block(loc, blockLocation.getBlock());
                        blocks.add(block);
                    }
                }
            }
            return blocks;
        }
    We were simply calling blockLocation.subtract thinking that it would not update the original blockLocation, but it does. The solution is mind numbingly simple, instead of
    Code:
    blockLocation.subtract(start.getLocation());
    Use
    Code:
    blockLocation.clone().subtract(start.getLocation());
    And it should be all good.
     
    Xp10d3 likes this.
  8. Offline

    Xp10d3

    @CraftCreeper6 TYSM! It works :D Really appreciate your help man. Tyy
    [​IMG]
     
  9. Offline

    CraftCreeper6

    @Xp10d3
    Awesome,
    one thing I can see right away though is that the stairs are not facing the right way, make sure you update all of the information of the new block, including its state and data, when you paste.
     
    Xp10d3 likes this.
  10. Offline

    Xp10d3

    Yep I'm planning on storing the block data in the Block class. That's the next step haha.
     

Share This Page