Exponential Chunk Loading?

Discussion in 'Plugin Development' started by BaddCamden, Aug 8, 2022.

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

    BaddCamden

    OK so I am creating a configurable custom ores plugin where you can add/remove custom ores from your plugin at any point in time. I am having an issue however, whenever I loop through a chunk and and the ore veins in, it seems to me that the chunks near to it are also being loaded as when I check the System.nanoTime() from when the first chunk was loaded subtracted when it was suppose to finish, it is some insane number that is around 38 seconds or 38000000000 nano seconds, which is around the time it takes to kick me and for the chunks to stop loading out of lag. Each chunk takes only about 50000 nano seconds to load the logic I am using. I looked at my chunk database, and around 1300 chunks were loaded when the world just loaded! Any pointers to what could be loading more chunks?

    Code:
        @EventHandler
        public void onLoadChunk(ChunkLoadEvent event) {
         
            Chunk chunk = event.getChunk();
            long start1 = System.nanoTime();
            List<Location> blocks = new ArrayList<Location>();
            List<String> ores = new ArrayList<String>();
         
            Double dKey = new Double(event.getChunk().getX(), event.getChunk().getZ());
            if(!additionsC.containsKey(dKey)) {
                createChunkDatabase(dKey, new ArrayList<String>());
            }
         
         
            for(String ore : config.getConfigurationSection("CustomOres").getKeys(false)) {
                if(additionsC.get(dKey).loadedOres.contains(ore)) {
                    continue;
                }
                CustomOreStuff stuff = customOreStuffList.get(ore);
                onLog.info("1: "+ (System.nanoTime()-start1));
                int X, Y, Z;
                boolean isStone;
             
             
                for (int i = 0; i < (stuff.rarity * rand.nextDouble()); i++) {
                    X = rand.nextInt(15);
                    Z = rand.nextInt(15);
                    Y = rand.nextInt(stuff.maxYLevel - stuff.minYLevel)+stuff.minYLevel;
                    Block b;
                    try {
                        b = chunk.getBlock(X, Y, Z);
                    } catch(IllegalArgumentException e) {
                        continue;
                    }
                    if (stuff.replacableBlocks.contains(b.getType())) {
                        int size = rand.nextInt(stuff.maxSize - stuff.minSize) + stuff.minSize;
                        isStone = true;
                        while (isStone) {
                            onLog.info("2: "+ (System.nanoTime()-start1));
                            b.setType(stuff.oreBlock);
                         
                            blocks.add(b.getLocation());
                            ores.add(ore);
                         
                            if (size >= 0)  {
                                switch (rand.nextInt(5)) {
                                    case 0: X++; break;
                                    case 1: Y++; break;
                                    case 2: Z++; break;
                                    case 3: X--; break;
                                    case 4: Y--; break;
                                    case 5: Z--; break;
                                }
                                try {
                                    b = chunk.getBlock(X, Y, Z);
                                } catch(IllegalArgumentException e) {
                                    break;
                                }
                                size--;
                                isStone = stuff.replacableBlocks.contains(b.getType());
                             
                            } else isStone = false;
                        }
    
                        onLog.info("3: "+ (System.nanoTime()-start1));
                    }
                }
                onLog.info("LoadYES");
             
             
            }
            additionsC.get(dKey).loadedOres.addAll(config.getConfigurationSection("CustomOres").getKeys(false));
            onLog.info("Before Elapsed Time in nano seconds: "+ (System.nanoTime()-start1));
            if(blocks.size() == 0) {
                for(int i = 0; i < blocks.size(); i++) {
                    Location b = blocks.get(i);
                    createOreDatabase(ores.get(i), b, 360);
                 
                }
            }
            long end1 = System.nanoTime();   
            onLog.info("After Elapsed Time in nano seconds: "+ (end1-start1));
            ticks.add(end1-start1);
         
            //mainPlugin.saveDataBase("block");
        }
    [CODE]
    Ignore the terrible names for some of the stuff, will fix later. Just tired rn after all of this lol


    EDIT:
    Not sure but I found this in a thread dump from Paper:
    Code:
    net.minecraft.world.level.redstone.CollectingNeighborUpdater$MultiNeighborUpdate.runNext(CollectingNeighborUpdater.java:121)
    [04:09:35 ERROR]: net.minecraft.world.level.redstone.CollectingNeighborUpdater.runUpdates(CollectingNeighborUpdater.java:79)
    [04:09:35 ERROR]: net.minecraft.world.level.redstone.CollectingNeighborUpdater.addAndRun(CollectingNeighborUpdater.java:63)
    [04:09:35 ERROR]: net.minecraft.world.level.redstone.CollectingNeighborUpdater.updateNeighborsAtExceptFromFacing(CollectingNeighborUpdater.java:45)
    [04:09:35 ERROR]: net.minecraft.server.level.ServerLevel.updateNeighborsAt(ServerLevel.java:1706)
    [04:09:35 ERROR]: net.minecraft.server.level.ServerLevel.blockUpdated(ServerLevel.java:2327)
    [04:09:35 ERROR]: net.minecraft.world.level.Level.notifyAndUpdatePhysics(Level.java:638)
    [04:09:35 ERROR]: net.minecraft.world.level.Level.setBlock(Level.java:605)
    [04:09:35 ERROR]: net.minecraft.world.level.Level.setBlock(Level.java:514)
    [04:09:35 ERROR]: org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setTypeAndData(CraftBlock.java:210)
    [04:09:35 ERROR]: org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setTypeAndData(CraftBlock.java:195)
    [04:09:35 ERROR]: org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setBlockData(CraftBlock.java:191)
    [04:09:35 ERROR]: org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setType(CraftBlock.java:180)
    [04:09:35 ERROR]: org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.setType(CraftBlock.java:174)
    [04:09:35 ERROR]: CustomItemsAPI.jar//me.BaddCamden.CustomItemsAPI.RegisterEvents.onLoadChunk(RegisterEvents.java:311)
    [04:09:35 ERROR]: com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor9.execute(Unknown Source)
    [04:09:35 ERROR]: org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:75)
    [CODE]
    I think the ore generation is loading nearby chunks in-case that it as redstone. May not be but will try
     
    Last edited: Aug 8, 2022
  2. Offline

    Kars

    Maybe you are adding the same chunks multiple times.
     
Thread Status:
Not open for further replies.

Share This Page