chiniissweet

In this mod tnt will blow randomly around the player's head every 10 secs!!

Kodari AI
KodariJan 3 at 6:26 am 2,376 (v2)

I’ll create a chaotic TNT mod that spawns explosions around players’ heads every 10 seconds.

RandomHeadTnt
A chaotic Fabric mod that spawns primed TNT at random positions around each player's head every 10 seconds. The TNT immediately begins its fuse countdown and explodes, creating constant mayhem and unpredictable destruction. Perfect for adding extreme difficulty and chaos to any survival world.

Project created! Every 10 seconds, TNT will spawn randomly within a 4-block radius around each player’s head and explode after 2 seconds. Build with ./gradlew build.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 143
src/main/java/com/randomheadtnt/RandomHeadTnt.java
package com.randomheadtnt;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.TntEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;

import java.util.Random;

public class RandomHeadTnt implements ModInitializer {
	private static final int TICK_INTERVAL = 200;
	private int tickCounter = 0;
	private final Random random = new Random();

	@Override
	public void onInitialize() {
		ServerTickEvents.END_WORLD_TICK.register(this::onWorldTick);
	}

	private void onWorldTick(ServerWorld world) {
		tickCounter++;

		if (tickCounter >= TICK_INTERVAL) {
			tickCounter = 0;

			for (ServerPlayerEntity player : world.getPlayers()) {
				spawnTntAroundHead(player);
			}
		}
	}

	private void spawnTntAroundHead(ServerPlayerEntity player) {
		Vec3d playerPos = player.getPos();
		double headY = playerPos.y + player.getStandingEyeHeight();

		double offsetX = (random.nextDouble() - 0.5) * 4.0;
		double offsetY = (random.nextDouble() - 0.5) * 2.0;
		double offsetZ = (random.nextDouble() - 0.5) * 4.0;

		double tntX = playerPos.x + offsetX;
		double tntY = headY + offsetY;
		double tntZ = playerPos.z + offsetZ;

		TntEntity tnt = new TntEntity(player.getWorld(), tntX, tntY, tntZ, null);
		tnt.setFuse(40);

		player.getWorld().spawnEntity(tnt);
	}
}