zvxcusersd

make me a minecraft mod that every 60 secs 100 tnt spawn on top of me lit only give a toggle to turn this on and off no timer control

Kodari AI
KodariMay 14 at 1:56 pm 13,971 (v2)

I’ll create a chaos mod that spawns 100 lit TNT above players every 60 seconds with a toggle command.

TntRain
A chaos mod that spawns 100 lit TNT entities directly above the player every 60 seconds. Players can toggle the effect on or off using the /tntrain command. Perfect for testing blast protection, creating chaotic gameplay scenarios, or just watching the world burn. Simple one-command interface with per-player toggle states that persist during the session.

Now I’ll create the TNT rain mod with a simple toggle command.

✅ TNT Rain mod created!

Features:

  • Command: /tntrain toggles the effect on/off for each player

  • Timing: Every 60 seconds (1200 ticks), spawns 100 TNT entities

  • Spawn pattern: TNT spawns 10 blocks above the player, spread randomly in a 4-block radius

  • Fuse time: 80 ticks (4 seconds) before explosion

  • Notifications: Red message when enabled, green when disabled, action bar message when TNT spawns

The mod tracks per-player toggle states and only spawns TNT for players who have it enabled. TNT is fully lit and will explode after 4 seconds!

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 203
src/main/java/com/example/tntrain/TntRainMod.java
package com.example.tntrain;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.TntEntity;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import com.mojang.brigadier.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class TntRainMod implements ModInitializer {
    public static final String MOD_ID = "tntrain";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    private static final Map<UUID, Boolean> playerToggles = new HashMap<>();
    private static int tickCounter = 0;
    private static final int TNT_SPAWN_INTERVAL = 1200;
    private static final int TNT_COUNT = 100;
    private static final double SPAWN_HEIGHT_OFFSET = 10.0;

    @Override
    public void onInitialize() {
        LOGGER.info("TNT Rain mod initialized!");

        registerCommand();
        registerTickHandler();
    }

    private void registerCommand() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
            dispatcher.register(CommandManager.literal("tntrain")
                .executes(context -> {
                    ServerPlayerEntity player = context.getSource().getPlayerOrThrow();
                    UUID playerId = player.getUuid();

                    boolean currentState = playerToggles.getOrDefault(playerId, false);
                    boolean newState = !currentState;
                    playerToggles.put(playerId, newState);

                    if (newState) {
                        context.getSource().sendFeedback(
                            () -> Text.literal("§cTNT Rain ENABLED! 100 TNT will spawn above you every 60 seconds."),
                            false
                        );
                    } else {
                        context.getSource().sendFeedback(
                            () -> Text.literal("§aTNT Rain disabled."),
                            false
                        );
                    }

                    return Command.SINGLE_SUCCESS;
                })
            );
        });
    }

    private void registerTickHandler() {
        ServerTickEvents.END_SERVER_TICK.register(server -> {
            tickCounter++;

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

                for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
                    UUID playerId = player.getUuid();
                    if (playerToggles.getOrDefault(playerId, false)) {
                        spawnTntRain(player);
                    }
                }
            }
        });
    }

    private void spawnTntRain(ServerPlayerEntity player) {
        double baseX = player.getX();
        double baseY = player.getY() + SPAWN_HEIGHT_OFFSET;
        double baseZ = player.getZ();

        for (int i = 0; i < TNT_COUNT; i++) {
            double offsetX = (Math.random() - 0.5) * 4.0;
            double offsetZ = (Math.random() - 0.5) * 4.0;

            TntEntity tnt = new TntEntity(
                player.getServerWorld(),
                baseX + offsetX,
                baseY,
                baseZ + offsetZ,
                player
            );

            tnt.setFuse(80);
            player.getServerWorld().spawnEntity(tnt);
        }

        player.sendMessage(Text.literal("§c§l100 TNT spawned above you!"), true);
    }

    public static boolean isEnabled(UUID playerId) {
        return playerToggles.getOrDefault(playerId, false);
    }
}