65 lines
2.9 KiB
Java
65 lines
2.9 KiB
Java
package dev.agatharose.asbestos.scheduler;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import dev.agatharose.asbestos.Asbestos;
|
|
import dev.agatharose.asbestos.config.AsbestosConfig;
|
|
import me.shedaniel.autoconfig.AutoConfig;
|
|
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() {
|
|
ServerTickEvents.END_SERVER_TICK.register(server -> {
|
|
// load mod config from the toml file
|
|
AsbestosConfig config = AutoConfig.getConfigHolder(AsbestosConfig.class).getConfig();
|
|
|
|
// run every 5 seconds by default
|
|
if (server.getTicks() % (config.mesothelioma.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 >= (config.mesothelioma.threshold / 2)) {
|
|
// give the player infinite mesothelioma effect
|
|
player.addStatusEffect(new StatusEffectInstance(Asbestos.MESOTHELIOMA_EFFECT, 32767));
|
|
}
|
|
|
|
// don't have to check for asbestos if the player is safe from it
|
|
if (Asbestos.isProtectedFromAsbestos(player)) {
|
|
return;
|
|
}
|
|
|
|
int offset = config.mesothelioma.offset;
|
|
|
|
// 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.HARMFUL_PASSIVE_BLOCKS).contains(block)) {
|
|
Asbestos.MESOTHELIOMA.get(player).setMesothelioma(exposure + 1);
|
|
|
|
break findasbestos;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|