package dev.agatharose.asbestos.scheduler; import java.util.Arrays; import dev.agatharose.asbestos.Asbestos; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.minecraft.block.Block; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; public class MesotheliomaSched { public static void init() { // how many blocks around the player will be checked // TODO: move into mod config int offset = 3; int period = 5; int threshold = 180; ServerTickEvents.END_SERVER_TICK.register(server -> { // run every 5 seconds if (server.getTicks() % (period * 20) == 0) { server.getWorlds().forEach(world -> { world.getPlayers().forEach(player -> { // get the player's asbestos exposure level int exposure = Asbestos.MESOTHELIOMA.get(player).getMesothelioma(); // let the player know that they may be entitled to financial compensation... // before it's too late if (exposure >= (threshold / 2)) { // give the player infinite mesothelioma effect player.addStatusEffect(new StatusEffectInstance(Asbestos.MESOTHELIOMA_EFFECT, 32767)); } // iterate over every block in the cuboid findasbestos: for (int i = -offset; i < offset; i++) { for (int j = -offset; j < offset; j++) { for (int k = -offset; k < offset; k++) { // offset player position Vec3d offsetPos = player.getPos().add(i, j, k); BlockPos pos = new BlockPos(offsetPos); Block block = world.getBlockState(pos).getBlock(); if (Arrays.asList(Asbestos.DANGEROUS_BLOCKS).contains(block)) { Asbestos.MESOTHELIOMA.get(player).setMesothelioma(exposure + 1); break findasbestos; } } } } }); }); } }); } }