Solved Creating ChunkID's

Discussion in 'Spigot Plugin Development' started by CodingCyClone, Jun 26, 2021.

  1. Background info
    I am working with adding chunks to a map and to do this I needed to create a custom id for each chunk which allows me to use events to check if something is broken in claimed chunk. Anyways this part works perfectly but recently I needed to add a radius of chunks to a map as well which for some reason breaks the whole thing.
    Code (Text):
    public void addOtherBaseClaims(String coordinates, String faction, Player p) {
            Chunk startingChunk = p.getWorld().getChunkAt(p.getLocation());
            World world = startingChunk.getWorld();
            int[] offset = {-16, 0, 16};
            String[] cords = coordinates.split(" ");
            int baseX = Integer.parseInt(cords[0]);
            int baseZ = Integer.parseInt(cords[1]);

            for(int x : offset) {
                for(int z : offset) {
                    int xCombined = baseX + x;
                    int zCombined = baseZ + z;
                    Chunk chunk = world.getChunkAt(xCombined, zCombined);
                    long chunkID = (long) chunk.getX() & 0xffffffffL | ((long) chunk.getZ() & 0xffffffffL) << 32;
                    long chunkID2 = (long) startingChunk.getX() & 0xffffffffL | ((long) startingChunk.getZ() & 0xffffffffL) << 32;
                    baseClaimManager.setOtherBaseChunks(chunkID, faction);
                    System.out.println("ChunkID:" + chunkID + " chunkX:" + chunk.getX() + " chunkZ:" + chunk.getZ());
                    System.out.println("ChunkId:" + chunkID + " ChunkID2:" + chunkID2);

                }
            }
        }

    Right now I am getting the x and z cords of the center right block of the chunk and passing them into the method as a string labeled "coordinates" along with the actual player and faction. Then I have an offset set in blocks of 16 which means it should add 9 chunks around the player to the map (which it does). Then I have the chunkID long value which is suppose to generate the custom chunk id but for some reason it creates the wrong id. To debug this I created the chunkID2 long value which is how I normally create chunkID's which has always worked (by using the chunk the player is standing in). The issue is the chunkID long value creates all wrong id's for some reason.
    Code (Text):
    [11:58:07 INFO]: ChunkID:-30064772264 chunkX:-1192 chunkZ:-8

    [11:58:07 INFO]: ChunkId:-30064772264 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:38654704472 chunkX:-1192 chunkZ:8

    [11:58:07 INFO]: ChunkId:38654704472 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:107374181208 chunkX:-1192 chunkZ:24

    [11:58:07 INFO]: ChunkId:107374181208 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:-30064772248 chunkX:-1176 chunkZ:-8

    [11:58:07 INFO]: ChunkId:-30064772248 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:38654704488 chunkX:-1176 chunkZ:8

    [11:58:07 INFO]: ChunkId:38654704488 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:107374181224 chunkX:-1176 chunkZ:24

    [11:58:07 INFO]: ChunkId:107374181224 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:-30064772232 chunkX:-1160 chunkZ:-8

    [11:58:07 INFO]: ChunkId:-30064772232 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:38654704504 chunkX:-1160 chunkZ:8

    [11:58:07 INFO]: ChunkId:38654704504 ChunkID2:4294967222

    [11:58:07 INFO]: ChunkID:107374181240 chunkX:-1160 chunkZ:24

    [11:58:07 INFO]: ChunkId:107374181240 ChunkID2:4294967222

    That being said the one to pay attention to is this following one because thats exactly where I was standing when I claimed (I also made the blockPlaceEvent send a message of the correct chunkID to the player which verifies my findings).
    Code (Text):
    [11:58:07 INFO]: ChunkID:38654704488 chunkX:-1176 chunkZ:8

    [11:58:07 INFO]: ChunkId:38654704488 ChunkID2:4294967222


    Main Question
    I just wanted to make sure to give enough background info to my problem but anyways my problem is I dont know why these two systems are creating different id's even though they are using the same coordinates. The only thing thats different is that I am using a different way to get the world but they should still be the same so I dont know what the issue is any ideas?