Kuroneko

tạo cho tôi 1 file totem 3D có thể chỉnh sound totem

Kodari AI
KodariSep 12 at 3:52 pm 1
TotemSoundCustomizer
A Minecraft plugin that adds a customizable 3D totem system with adjustable sound effects. Players can configure the totem's appearance, size, and rotation through commands, while the plugin plays custom sounds when the totem activates. Features include per-player totem configuration, sound selection from a configurable list, volume and pitch adjustment, and persistent storage of settings. The plugin provides an intuitive command interface for setting totem properties and managing sound profiles, enhancing the player experience with personalized totem interactions.
  1. Tạo plugin Paper bắt sự kiện dùng Totem và phát sound cấu hình được.

  2. Thêm lệnh /totem3d reload để reload sound không cần restart server.

  3. Thêm resource pack model 3D thay thế Totem vanilla, dùng texture Totem có sẵn.

Đã tạo plugin Totem3D gồm:

  • Bắt sự kiện sử dụng Totem of Undying.

  • Cho phép chỉnh sound trong config.yml:

    YAML
    sound:
      enabled: true
      key: minecraft:item.totem.use
      volume: 1.0
      pitch: 1.0
    
  • Reload bằng lệnh:

    Plain Text
    /totem3d reload
    
  • Có model Totem 3D tùy chỉnh trong resource pack:

    Plain Text
    src/main/resources/assets/minecraft/models/item/totem_of_undying.json
    
  • Dùng Paper API 1.21.4 và Java 21.

Để model 3D hiển thị cho người chơi, phần src/main/resources cần được đóng gói hoặc đưa vào resource pack server.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
8 229
src/main/java/com/kodari/totem3d/Totem3DPlugin.java
package com.kodari.totem3d;

import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Locale;

public final class Totem3DPlugin extends JavaPlugin implements Listener, CommandExecutor {

    private Sound totemSound;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadSound();
        getServer().getPluginManager().registerEvents(this, this);

        if (getCommand("totem3d") != null) {
            getCommand("totem3d").setExecutor(this);
        }
    }

    private void loadSound() {
        totemSound = null;

        if (!getConfig().getBoolean("sound.enabled", true)) {
            return;
        }

        String configuredKey = getConfig().getString("sound.key", "minecraft:item.totem.use");
        NamespacedKey key = NamespacedKey.fromString(configuredKey);

        if (key == null && !configuredKey.contains(":")) {
            key = NamespacedKey.minecraft(configuredKey.toLowerCase(Locale.ROOT));
        }

        if (key != null) {
            totemSound = Registry.SOUNDS.get(key);
        }

        if (totemSound == null) {
            getLogger().warning("Unknown Totem sound key: " + configuredKey);
        }
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onTotemUse(EntityResurrectEvent event) {
        if (totemSound == null) {
            return;
        }

        Entity entity = event.getEntity();
        if (!(entity instanceof Player player)) {
            return;
        }

        float volume = (float) getConfig().getDouble("sound.volume", 1.0D);
        float pitch = (float) getConfig().getDouble("sound.pitch", 1.0D);
        player.playSound(player.getLocation(), totemSound, volume, pitch);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length != 1 || !args[0].equalsIgnoreCase("reload")) {
            sender.sendMessage("§eDùng: /totem3d reload");
            return true;
        }

        if (!sender.hasPermission("totem3d.reload")) {
            sender.sendMessage("§cBạn không có quyền dùng lệnh này.");
            return true;
        }

        reloadConfig();
        loadSound();
        sender.sendMessage("§aĐã reload cấu hình Totem3D.");
        return true;
    }
}