ImZaiLetsPlayYT

create a pickaxe called rubypickaxe that can smelt in furnace and make a ruby ore you can smelt in furnace

Kodari AI
KodariNov 4 at 7:38 pm 1
RubyPickaxePlugin
A Minecraft plugin that introduces a new Ruby Pickaxe tool and Ruby Ore block. The Ruby Pickaxe is a craftable, high-durability tool that automatically smelts mined ores in the furnace, providing smelted ingots directly. The plugin adds Ruby Ore generation in the world, which can be mined and smelted into Ruby Gems. Includes custom crafting recipes, item textures, ore generation, and smelting functionality for both the Ruby Ore and the Ruby Pickaxe's auto-smelt ability.
  • Add Ruby Ore, Ruby and Ruby Pickaxe items.

  • Register furnace and crafting recipes, plus a command to obtain the items.

Created Ruby Ore, Ruby and Ruby Pickaxe items. Smelt ore into rubies, craft a pickaxe with three rubies and two sticks, or smelt the pickaxe back into a ruby.

Operators can use /ruby give <ore|ruby|pickaxe>. Ruby Ore is an obtainable item, not a naturally generating block.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 112
src/main/java/com/kodari/ruby/RubyPlugin.java
package com.kodari.ruby;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

public final class RubyPlugin extends JavaPlugin {
    private NamespacedKey itemKey;

    @Override
    public void onEnable() {
        itemKey = new NamespacedKey(this, "ruby_item");
        ItemStack ore = createItem("IRON_ORE", "Ruby Ore", "ore");
        ItemStack ruby = createItem("RED_DYE", "Ruby", "ruby");
        ItemStack pickaxe = createItem("IRON_PICKAXE", "Ruby Pickaxe", "pickaxe");

        Bukkit.addRecipe(new FurnaceRecipe(new NamespacedKey(this, "ruby_from_ore"), ruby,
                new RecipeChoice.ExactChoice(ore), 0.7f, 200));
        Bukkit.addRecipe(new FurnaceRecipe(new NamespacedKey(this, "ruby_from_pickaxe"), ruby,
                new RecipeChoice.ExactChoice(pickaxe), 0.1f, 200));

        ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "ruby_pickaxe"), pickaxe);
        recipe.shape("RRR", " S ", " S ");
        recipe.setIngredient('R', new RecipeChoice.ExactChoice(ruby));
        recipe.setIngredient('S', material("STICK"));
        Bukkit.addRecipe(recipe);
    }

    private Material material(String name) {
        return XMaterial.matchXMaterial(name).map(XMaterial::parseMaterial)
                .orElseThrow(() -> new IllegalStateException("Missing material: " + name));
    }

    private ItemStack createItem(String material, String name, String id) {
        ItemStack item = new ItemStack(material(material));
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(ChatColor.RED + name);
        meta.getPersistentDataContainer().set(itemKey, PersistentDataType.STRING, id);
        item.setItemMeta(meta);
        return item;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }
        if (args.length != 2 || !args[0].equalsIgnoreCase("give")) {
            sender.sendMessage(ChatColor.RED + "Usage: /ruby give <ore|ruby|pickaxe>");
            return true;
        }
        ItemStack item;
        switch (args[1].toLowerCase(java.util.Locale.ROOT)) {
            case "ore": item = createItem("IRON_ORE", "Ruby Ore", "ore"); break;
            case "ruby": item = createItem("RED_DYE", "Ruby", "ruby"); break;
            case "pickaxe": item = createItem("IRON_PICKAXE", "Ruby Pickaxe", "pickaxe"); break;
            default:
                sender.sendMessage(ChatColor.RED + "Choose ore, ruby, or pickaxe.");
                return true;
        }
        Player player = (Player) sender;
        for (ItemStack leftover : player.getInventory().addItem(item).values()) {
            player.getWorld().dropItemNaturally(player.getLocation(), leftover);
        }
        sender.sendMessage(ChatColor.GREEN + "Ruby item received.");
        return true;
    }
}