Noelxg Reyes

Create mod in Oneblock de terror i que cada 15 segundos sea un mod

Kodari AI
KodariOct 31 at 12:38 am 1
OneBlockHorrorSurvival
Creates a terrifying OneBlock survival experience where players spawn on a single floating block that regenerates every 15 seconds. Each regeneration cycle introduces random horror elements including nightmarish mobs, environmental hazards, sanity-draining effects, and Lovecraftian entities. Features a sanity system that decreases when witnessing horrors, unique horror-themed mobs with custom AI, atmospheric effects like fog and whispers, and escalating difficulty waves. Players must gather resources from the regenerating block while surviving increasingly dangerous supernatural threats. Includes configurable horror intensity, spawn rates, and sanity recovery mechanics.

Crearé un plugin de OneBlock de terror que genere un mob hostil cerca de cada jugador cada 15 segundos.

Creé HorrorOneBlock: genera un mob hostil cerca de cada jugador cada 15 segundos. El intervalo, el radio y los tipos de mob se configuran en config.yml. Interpreté «mod» como «mob».

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 126
src/main/java/com/kodari/horroroneblock/HorrorOneBlockPlugin.java
package com.kodari.horroroneblock;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class HorrorOneBlockPlugin extends JavaPlugin {
    private BukkitTask spawnTask;
    private List<EntityType> mobTypes;
    private int spawnRadius;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadSettings();

        long intervalTicks = Math.max(1, getConfig().getLong("spawn-interval-seconds", 15)) * 20;
        spawnTask = getServer().getScheduler().runTaskTimer(this, this::spawnForOnlinePlayers, intervalTicks, intervalTicks);
        getLogger().info("Horror OneBlock mob spawns enabled.");
    }

    @Override
    public void onDisable() {
        if (spawnTask != null) {
            spawnTask.cancel();
        }
    }

    private void loadSettings() {
        spawnRadius = Math.max(1, getConfig().getInt("spawn-radius", 5));
        mobTypes = new ArrayList<>();

        for (String name : getConfig().getStringList("mobs")) {
            try {
                mobTypes.add(EntityType.valueOf(name.trim().toUpperCase()));
            } catch (IllegalArgumentException exception) {
                getLogger().warning("Ignoring unknown mob type in config: " + name);
            }
        }

        if (mobTypes.isEmpty()) {
            getLogger().warning("No valid mobs configured; using ZOMBIE.");
            mobTypes.add(EntityType.ZOMBIE);
        }
    }

    private void spawnForOnlinePlayers() {
        for (Player player : getServer().getOnlinePlayers()) {
            Location location = findSpawnLocation(player);
            if (location != null) {
                EntityType mob = mobTypes.get(ThreadLocalRandom.current().nextInt(mobTypes.size()));
                location.getWorld().spawnEntity(location, mob);
            }
        }
    }

    private Location findSpawnLocation(Player player) {
        World world = player.getWorld();
        Location playerLocation = player.getLocation();
        ThreadLocalRandom random = ThreadLocalRandom.current();

        for (int attempt = 0; attempt < 10; attempt++) {
            int x = playerLocation.getBlockX() + random.nextInt(-spawnRadius, spawnRadius + 1);
            int z = playerLocation.getBlockZ() + random.nextInt(-spawnRadius, spawnRadius + 1);
            Block ground = world.getHighestBlockAt(x, z);

            if (!ground.getType().isSolid()) {
                continue;
            }

            Location spawnLocation = ground.getLocation().add(0.5, 1, 0.5);
            if (spawnLocation.getBlock().isPassable() && spawnLocation.clone().add(0, 1, 0).getBlock().isPassable()) {
                return spawnLocation;
            }
        }

        return null;
    }
}