@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
)
);
}
}
}
By
Nofraag · 6 minutes ago 6 min
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.