#Land Plot Math

1 messages · Page 1 of 1 (latest)

surreal current
#

Hey guys! This is perhaps more of a math problem...

I'm working on a project which involves something like land plots, which can each be represented by an x and z coordinate (shown in black below). I also want to be able to represent each plot with a single number, which sorta makes a spiral pattern (shown in red below).

I'm trying to figure out the best way to convert from black to red numbers, and from red back to black numbers. It feels like there should be some simple solution, but after scratching my head for a few hours I decided I might as well ask for some guidance 😅

Any help is much appreciated :)

#

oh I can't send images

#

well this is akward 😬

boreal bear
#

wha?

surreal current
#

Yeah it doesn't make sense without my reference image xD

boreal bear
#

also you need to ping people if you want them to be here

#

i mean, they can still join

viscid sonnet
#

Gotta verify to send pics, it's quick and easy

surreal current
#

oh ok how do I do that

#

ok brb

#

ah here we go

#

here's the image :)

velvet jackal
#

oh i've just coded this today

#

hold on

surreal current
#

:D

velvet jackal
#

i'm reimplementing it so it's a bit messy, lemme find the one i sent earlier in general

#
        public void execute(Player player, String[] args) {
            iteration = 0;
            int arg1 = Integer.parseInt(args[0]);
            Location loc = player.getLocation().getBlock().getLocation();

            Bukkit.broadcastMessage(String.valueOf(System.currentTimeMillis()));
            for(iteration = 0; iteration < arg1; iteration++){
                //loc.getBlock().setType(Material.GOLD_BLOCK);
                changeLocation(loc);
            }
            Bukkit.broadcastMessage(String.valueOf(System.currentTimeMillis()));
        }

        private void changeLocation(Location location){
            switch (getDirection()) {
                case 0 -> location.add(distance, 0, 0);
                case 1 -> location.add(0, 0, distance);
                case 2 -> location.add(-distance, 0, 0);
                case 3 -> location.add(0, 0, -distance);
            }
        }

        private int getDirection(){
            int direction = 0;
            int iteration = this.iteration;
            for(int j = 1; true; j++) {
                for(int k = 0; k < 2; k++) {
                    iteration -= j;
                    if (iteration < 0) return direction;
                    direction = (direction + 1) % 4;
                }

            }
        }
#

something like this

#

the execute method is a method from a command api of mine

#

so you probably want to change it

#

the arg1 is basically how many "plots" i want to generate

#

there should also be a global field for the distance each plot should have

#

i'm still working on this code, maybe when i have a better version i can send it but this should work fine

surreal current
#

I'll have a look thru this, tyvm 👍