Setting blockdata causes recursive population

Discussion in 'Spigot Plugin Development' started by cdwpapd, Jan 7, 2020.

  1. As the title says. When I try to set blockdata to a block (in this case using setSnowy on grass) causes the populator to freak out
    Code (Java):
    public class SnowPopulator implements IPopulator {
        private static void generateSnow(ISimpleWorld world, Random rand, double[] temperatures, int chunkStartX, int chunkStartZ) {

            for (int blockX = chunkStartX; blockX < chunkStartX + 16; blockX++) {
                for (int blockZ = chunkStartZ; blockZ < chunkStartZ + 16; blockZ++) {
                    int localX = blockX - chunkStartX;
                    int localZ = blockZ - chunkStartZ;
                    int blockY = getHighestSolidOrLiquidBlock(world, blockX, blockZ);
                    double temp = temperatures[(localX << 4) | localZ] - (blockY - 64) / 64D * 0.3D;
                    Material blockBelow = world.getType(blockX, blockY - 1, blockZ);
                    if ((temp < 0.5D) &&
                            blockY > 0 && blockY < 128 &&
                            world.isEmpty(blockX, blockY, blockZ) &&
                            blockBelow.isSolid() && blockBelow != ICE) {
                        world.setType(blockX, blockY, blockZ, SNOW);
                        if(blockBelow == GRASS_BLOCK) {
                            BlockState snowgrass = world.getBlockState(blockX, blockY - 1, blockZ);
                            Snowable ssnow = (Snowable) snowgrass.getBlockData();
                            ssnow.setSnowy(true);
                            snowgrass.setBlockData(ssnow);
                            snowgrass.update();
                        }
                    }
                }
            }
        }
    Removing everything under the line 'if(blockBelow == GRASS_BLOCK) {' produces no errors, however no blockdata is set. In case if it's relevant, here's the bit of code that gets triggered by this
    Code (Java):
        void createStateFor(int chunkX, int chunkZ) {
            this.primaryState = PopulatorState.forChunk(this.world, this.wcm, chunkX, chunkZ);
            this.allStates.add(primaryState);
            if (allStates.size() > 1) {
                Generator.logger().warning("Already populating chunk ("+chunkX+", "+chunkZ+"). Recursive generation may cause issues.");
            }
        }
     
  2. md_5

    Administrator Developer

    update(false) so physics doesn't run
     
    • Informative Informative x 1
  3. You're not only using the Spigot API, why is that?

    EDIT: I'm curious why you need to use IPopulator.
     
  4. It didn't seem to change anything
    All it does is get and set blocks