2 hours ago2 hr @SubscribeEvent public void onChunkLoad(ChunkEvent.Load event) { if (!(event.getLevel() instanceof Level level) || !event.isNewChunk()) return; if (level.isClientSide()) { ChunkAccess chunk = event.getChunk(); ChunkPos pos = chunk.getPos(); Vector2i coordinatesToWorld = new Vector2i(pos.x * 16, pos.z * 16); Vector2i chunk_origin = new Vector2i( Math.floorMod(coordinatesToWorld.x, 512), Math.floorMod(coordinatesToWorld.y, 512) ); Vector2i region_coordinates = new Vector2i( pos.getRegionX(), pos.getRegionZ() ); int[] colors_data = new int[256]; for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int highestY = chunk.getHeight( Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, x, z ); BlockPos blockPos = pos.getBlockAt(x, highestY-1, z); BlockState state = level.getBlockState(blockPos); int colorsValue = getColorsValue(state); System.out.println("block: " + state.getBlock() + ", height: " + highestY); colors_data[z * 16 + x] = colorsValue; } } MinecraftServer server = ServerLifecycleHooks.getCurrentServer(); if (server != null) { ExampleMod.MOD_FOLDER.AttemptToModifyRegionArea( chunk_origin.x, chunk_origin.y, 16, 16, colors_data, new RegionRecord( level.dimension().location().toString(), server.getWorldData().getLevelName(), region_coordinates ) ); } } } Edited 2 hours ago2 hr by Nofraag
2 hours ago2 hr I am not sure butif (level.isClientSide()) { ... } here always return false (singleplayer is some kind of local server) - so this is used for client-thread stuff like changing GUIs or working with effectsSo this code block is completely ignored - to make sure, test it with LOGGER.info() lines or System.out.println()So if I am correct, just unwrap it from the if (level.isClientSide()) { ... } check Try my Modpack >>Link to Curseforge<<
1 hour ago1 hr Author 44 minutes ago, TileEntity said:I am not sure butif (level.isClientSide()) { ... }here always return false (singleplayer is some kind of local server) - so this is used for client-thread stuff like changing GUIs or working with effectsSo this code block is completely ignored - to make sure, test it with LOGGER.info() lines or System.out.println()So if I am correct, just unwrap it from the if (level.isClientSide()) { ... } checkno, no it does get reached the problem it's that chunk.getHeight for some reason returns -64 instead of the actual highest block on that position (the line System.out.println("block: " + state.getBlock() + ", height: " + highestY);) keeps printing block: minecraft:void_air, height: -64
42 minutes ago42 min If I had to guess, the client side chunk is not populated at the load time. As the server has to sync the data to the client.Why not just do all of this server side? I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.