pan__ p

build a plugin for a paper 1.21.11 minecraft. Do everything according to the instruction in the attached file.

📎 1 file 11,195 chars
📄
pasted-code-1789753103936.txt
txt 146 lines
▶
Minecraft Plugin Spec: Foundry

Build a single Paper/Spigot plugin (Java, Maven, targeting Paper 1.21.x) called Foundry. It adds two custom crafting stations and five leveling tools with a shared progression system. Everything below is one plugin, one JAR.

Core design principles
Custom items are tagged, not material-dependent. Every custom item (ingots, tools, etc.) carries a PersistentDataContainer string tag identifying it (e.g. "steel_ingot", "malachite_pickaxe"). Stations and drop logic check this tag, never the base Material — so a vanilla-obtained lookalike item is inert everywhere it matters.
Base items for "enchanted-look" tools are normally-unenchantable vanilla items (blocks work well, since blocks can't go in an enchanting table at all), then made unplaceable/unusable-as-a-block by the plugin. This is intentionally the only way to get an "enchanted" look on these items, since they can never receive a real vanilla enchantment.
Tool leveling uses discrete pre-built tier variants, not incremental stat mutation. Each level of a tool is its own fully-built ItemStack (own stats, own CustomModelData slot for a resource pack to skin). On leveling up, swap the held item for the next tier's variant, carrying over the level/progress PDC tags. Do not try to mutate one item's components in place across levels.
All five tools get simulated Mending from level 1 onward, since their base items can't be really enchanted — without it, a single durability break would permanently destroy an unrepeatable, heavily-leveled item.
Simulated enchantments (Fortune, Unbreaking, etc.) are not bound by vanilla's real level caps. These are plugin-tracked integers read by your own logic, not real enchantment components, so e.g. "Fortune 6" is fine even though vanilla caps at 3.
Threshold/leveling math

Each leveling tool has a progress counter and a level (1 up to a max). Threshold to advance from level n to n+1 follows this iterative curve (not closed-form — implement it exactly like this):

threshold = thresholdStart
multiplier = multiplierStart
for level in 1..maxLevel-1:
    # threshold is the amount of progress needed to leave `level`
    threshold *= multiplier
    multiplier *= multiplierDecay

Curves per tool:

Tool	thresholdStart	multiplierStart	multiplierDecay	Max level	Progress source
Pickaxe	10	5	0.9	13	blocks broken (incl. area-mining extras)
Sword	10	3	0.95	13	weighted kills (see below)
Axe	10	3	0.95	10 (not 13 — capped lower on purpose)	logs broken
Shovel	10	5	0.9	13	see Shovel-specific rule below
Hoe	10	3	0.95	13	mature crops harvested (not tilled)

Shovel progress rule (different from all others): the shovel gains progress only for blocks that actually yield a pickup into the inventory — not just any block broken. Additionally, once a shovel level grants a bonus-drop chance below 100%, that same chance percentage doubles as the chance for a bonus leveling point on that break.

Area-mining rule (Pickaxe): any block broken by an area-mining bonus (not just the originally targeted block) both drops its items normally AND counts toward the leveling threshold, same as a normally-broken block.

Station 1: Smeltery

Structure (multiblock): a cauldron as the core block, surrounded by Bricks on all 8 adjacent horizontal positions except the front-center, which stays open. Detect this in all 4 horizontal rotations so players can build facing any direction.

Fuel cost: every single craft, regardless of recipe, requires the cauldron to be completely full of lava, and fully drains it (back to empty) on craft. One full bucket = one output item.

Recipes:

Steel Ingot = 3 Iron Ingot + 5 Coal
Refined Diamond = 8 Diamond + 4 Gold Ingot + 4 Obsidian
Red40 = 1 Redstone + 64 Sugar
Malachite Ingot = 9 Malachite Shard (a custom item — see Malachite Magnet below for its source)
Station 2: Forge

Structure (multiblock): an anvil as the core block. Behind it (whichever side the matcher finds the pattern on, checked across all 4 rotations): 3 bars (Iron Bars), two blocks tall, positioned directly behind and at both back-diagonals. Flanking the anvil on its left and right: one Diamond Block each.

Recipes:

Malachite Magnet = 8 Steel Ingot + 2 Refined Diamond. Passive ability: while held in the offhand, every block the player mines has a 5% chance to additionally drop a Malachite Shard. This is the only source of Malachite Shards in the plugin — no dedicated ore block.
Malachite Pickaxe = 2 Breeze Rod + 3 Malachite Ingot. Base item: unenchantable/unplaceable Light.
Malachite Sword = 1 Breeze Rod + 2 Malachite Ingot. Base item: unenchantable/unplaceable Jigsaw.
Malachite Axe = 2 Breeze Rod + 3 Malachite Ingot. Base item: unenchantable/unplaceable Light, distinguished from the Pickaxe via a different CustomModelData range or a different simulated "enchant type" tag (optionally use unenchantable/unplaceable Grass instead, for a more visually distinct base if preferred).
Malachite Shovel = 2 Breeze Rod + 1 Malachite Ingot. Base item: unenchantable/unplaceable Command Block.
Malachite Hoe = 2 Breeze Rod + 2 Malachite Ingot. Base item: unenchantable/unplaceable Farmland (note: Farmland has no obtainable item form in vanilla survival at all, which is why it qualifies).
Tool ability lists
Pickaxe (13 levels)
Mining speed = bare hand
Mining speed = wooden pickaxe
Mining speed = stone pickaxe; also breaks the block directly below the one mined
Mining speed = iron pickaxe
Fortune I; mining speed = diamond pickaxe
Mining area becomes 1 high x 3 wide (a horizontal row, for strip-mining/tunneling — orient to the player's facing)
Fortune III
Flat mining speed value of 60 (instamines any cobblestone-hardness block)
Fortune IV
Mining area becomes 2x3 (2 blocks to the sides, 3 blocks below the target)
Swiftness II while held; mining speed doubles again
Extremely low chance (0.001%) per block to additionally mine out a "Leaf Fragment" item — seed item for a future Wands feature, not otherwise functional yet
Mining area becomes 3x3; leaf-fragment chance rises to 0.01%; Fortune VI; mining speed doubles again; item gains a permanent enchantment-glint visual
Sword (13 levels)
Damage = half a heart (1 damage point); attack range = 2 blocks
Damage doubles
Attack range = 3 blocks
Damage doubles; kills now count double toward leveling progress
Fire Aspect I on hit
Damage doubles (reaches 4 hearts / 8 damage at this point)
Attack range = 5 blocks
Damage doubles; kills now count double AGAIN — this STACKS with level 4's bonus, so from level 8 onward every kill counts 4x toward leveling
Fire Aspect II on hit; sweep-attack range doubles
Item gains permanent enchantment-glint visual; attack range = 7 blocks
Damage doubles; Swiftness I while held
Damage doubles; heals the player for the exact damage amount dealt on hit (lifesteal); Swiftness II while held (replaces Swiftness I)
Sweep range becomes 5x; damage becomes 3x (on top of the doubling chain); applies Poison V for 30 seconds to whatever is hit

Sword also visibly grows larger in its model across levels — not just stat buffs. Use CustomModelData per level to map to progressively larger blade models in the resource pack.

Weighted kill values (multiplied by the level's kill-count multiplier above): Ender Dragon = 500, Wither = 500, Warden = 250, Elder Guardian = 100, any other kill = 1.

Axe (10 levels — intentionally capped lower than the other tools)
Breaking speed on logs = bare hand; deals 1 damage (half a heart) per hit
Log-breaking speed doubles
Log-breaking speed doubles again
Leaf-clearing: when a log is broken, check the blocks immediately surrounding it. If more connected logs are found, do nothing extra. If no more logs are found but leaves are present, break those leaves and any leaves connected to them (flood-fill through adjacent leaf blocks — cap the search size, e.g. 200 blocks, to avoid lag on huge trees)
Log-breaking speed doubles again
Damage doubles
Looting II (simulated, on mob kills with this axe); damage doubles
Fortune V (simulated); 5% chance per log broken to yield double logs
Double-log chance rises to 15%
Tree-capitating: breaking one log breaks all logs connected to it (flood-fill through adjacent log blocks, same size cap as leaf-clearing)
Shovel (13 levels)
Mining power = wooden shovel
Mining power = stone shovel
Mining power = iron shovel
Mining power = diamond shovel
Mining power = golden shovel
Mining speed doubles
10% chance of double drops
50% chance of double drops
100% chance of double drops; 10% chance of a third drop
Third-drop chance rises to 50%
100% chance of three drops
1% chance per block mined to yield a "Wand Fragment" item (future Wands feature seed, not otherwise functional yet)
0.005% chance per block mined to yield a rarer "Supreme Wand Fragment" (distinct item from the regular fragment)
Hoe (13 levels — levels from harvesting MATURE crops, not from tilling)
Tills one dirt block at a time (baseline)
20% chance of double drops when harvesting a mature crop
Bonus-drop chance rises to 50%
Bonus-drop chance rises to 100%
50% chance of triple drops, 10% chance of a 4th drop
Triple-drop chance rises to 100%; 4th-drop chance rises to 50%
100% chance of quintuple (5x) drops
Automatically replants the crop after harvesting it
"Do Not Waste Diamonds On A Hoe" ability: 1% chance per crop harvested to also receive a Diamond
Breaks all other mature crops within a 1-block radius of the harvested one (also replanting/bonus-rolling each of those)
Swiftness II while held
Grants a "Cropper Egg" item — a spawn-egg-like item that places a special Villager with a small set of extremely expensive trades (costed entirely in crops). The actual trade list/villager will be configured manually by the developer after the fact via an admin command — just implement the mechanism to place a pre-configured Villager from a custom item.
Guaranteed 10x (decuple) drops on every harvest
Status effect: Lead Poisoning

Repurpose the vanilla Bad Luck potion effect's icon/name/visuals (via resource pack) to display as "Lead Poisoning" — the underlying registered effect ID stays Bad Luck (chosen because it has no meaningful vanilla gameplay footprint to fight against).

Trigger: eating a Red40 item grants:

A genuine vanilla Speed effect at amplifier level 40 for 10 seconds.
The reskinned Lead Poisoning effect for 2 minutes, which causes a small amount of direct damage once per second only while the player is moving ("muscle pain" — stationary players take no damage from it).

Also give Red40 (or the Lead Poisoning effect's tooltip) a flavor-text-only "miscarriage" warning line — purely cosmetic, no mechanical effect attached.

Explicitly out of scope for this build
Wands — a small future feature branch. Only the fragment items (Leaf Fragment, Wand Fragment, Supreme Wand Fragment) need to exist as droppable items now; no wand functionality itself.
Armor — planned to reuse the same tier-variant leveling system as the tools, but not part of this build.
"Stellar Foundry" progression (Steel → Stellarite → Infinity Ingot, plus an Alloyer station extending the Smeltery) — a larger expansion floated but deliberately deferred until this core plugin is finished and proven worth expanding.
Kodari AI
KodariSep 18 at 5:45 pm 22
Foundry
Foundry is a Paper 1.21 plugin adding two multiblock crafting stations and five leveling tools with a shared progression system. The Smeltery and Forge stations detect their structures across all rotations, consuming lava or materials for recipes like Steel Ingots and Malachite tools. Five tools (Pickaxe, Sword, Axe, Shovel, Hoe) feature discrete tier variants with simulated enchantments, area-mining, tree-capitating, and weighted kill progression. Tools use tagged custom items, unenchantable base materials, and simulated Mending. Red40 grants Speed 40 and a reskinned Lead Poisoning effect. Fragment items seed a future Wands feature.
  1. Scaffold a Maven Paper 1.21.x plugin with tagged custom items and resource-pack model-data tiers.

  2. Add Smeltery/Forge structure matching and recipe menus with fuel and tagged-ingredient validation.

  3. Implement progression, mining/harvest bonuses, combat effects, Mending simulation, Red40, and Lead Poisoning.

  4. Add Cropper Egg placement plus an admin command for configurable crop-trade villagers.

Built the Maven Paper 1.21.x Foundry plugin.

  • Added tagged custom ingots, materials, fragments, Cropper Egg, and five pre-built leveled tool variants with CustomModelData ranges.

  • Implemented Smeltery and Forge multiblock detection, craft menus, tagged recipe validation, and full-lava fuel consumption.

  • Added tool progression curves, mining/tree/harvest bonuses, magnet shard drops, sword combat scaling, simulated effects, and tool tier swaps.

  • Added consumable Red40 with Speed 40, Bad Luck–based Lead Poisoning movement damage, and cosmetic warning lore.

  • Added Cropper Villager placement and /foundry cropper settrade ... admin configuration.

  • Included pom.xml, plugin.yml, and configurable Cropper trade defaults.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
9 1,165
src/main/java/com/kodari/foundry/FoundryPlugin.java
package com.kodari.foundry;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.block.data.Levelled;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public final class FoundryPlugin extends JavaPlugin implements Listener {
    private CustomItems items;
    private ToolService tools;
    private NamespacedKey entityKey;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        this.entityKey = new NamespacedKey(this, "cropper_villager");
        this.items = new CustomItems(this);
        this.tools = new ToolService(this, items);
        getServer().getPluginManager().registerEvents(new FoundryListener(this), this);
        getCommand("foundry").setExecutor(new FoundryCommand(this));
        Bukkit.getScheduler().runTaskTimer(this, tools::refreshHeldEffects, 20L, 20L);
        Bukkit.getScheduler().runTaskTimer(this, tools::applyLeadPoisoningDamage, 20L, 20L);
    }

    public CustomItems items() {
        return items;
    }

    public ToolService tools() {
        return tools;
    }

    public NamespacedKey entityKey() {
        return entityKey;
    }

    public org.bukkit.inventory.MerchantRecipe cropperRecipe() {
        Material firstMaterial = material(getConfig().getString("cropper-trade.ingredient-one", "WHEAT"));
        Material secondMaterial = material(getConfig().getString("cropper-trade.ingredient-two", "CARROT"));
        Material resultMaterial = material(getConfig().getString("cropper-trade.result", "EMERALD"));
        if (firstMaterial == null || secondMaterial == null || resultMaterial == null) {
            throw new IllegalStateException("Cropper trade configuration contains an invalid material.");
        }
        ItemStack result = new ItemStack(resultMaterial, getConfig().getInt("cropper-trade.result-amount", 1));
        org.bukkit.inventory.MerchantRecipe recipe = new org.bukkit.inventory.MerchantRecipe(result, 999999);
        recipe.addIngredient(new ItemStack(firstMaterial, getConfig().getInt("cropper-trade.ingredient-one-amount", 64)));
        recipe.addIngredient(new ItemStack(secondMaterial, getConfig().getInt("cropper-trade.ingredient-two-amount", 64)));
        return recipe;
    }

    public Material material(String name) {
        return XMaterial.matchXMaterial(name.toUpperCase(Locale.ROOT))
                .map(XMaterial::parseMaterial)
                .orElse(null);
    }

    public boolean isType(Block block, String materialName) {
        Material material = material(materialName);
        return material != null && block.getType().equals(material);
    }

    public boolean isSmeltery(Block core) {
        if (!isType(core, "CAULDRON") && !isType(core, "LAVA_CAULDRON")) {
            return false;
        }
        int[][] directions = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
        for (int[] front : directions) {
            boolean matches = core.getRelative(front[0], 0, front[1]).getType().isAir();
            for (int x = -1; x <= 1 && matches; x++) {
                for (int z = -1; z <= 1; z++) {
                    if (x == 0 && z == 0 || x == front[0] && z == front[1]) {
                        continue;
                    }
                    matches = isType(core.getRelative(x, 0, z), "BRICKS");
                    if (!matches) {
                        break;
                    }
                }
            }
            if (matches) {
                return true;
            }
        }
        return false;
    }

    public boolean isForge(Block core) {
        if (!isType(core, "ANVIL")) {
            return false;
        }
        int[][] directions = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
        for (int[] behind : directions) {
            int sideX = -behind[1];
            int sideZ = behind[0];
            boolean matches = isType(core.getRelative(sideX, 0, sideZ), "DIAMOND_BLOCK")
                    && isType(core.getRelative(-sideX, 0, -sideZ), "DIAMOND_BLOCK");
            for (int side = -1; side <= 1 && matches; side++) {
                Block lower = core.getRelative(behind[0] + sideX * side, 0, behind[1] + sideZ * side);
                matches = isType(lower, "IRON_BARS") && isType(lower.getRelative(0, 1, 0), "IRON_BARS");
            }
            if (matches) {
                return true;
            }
        }
        return false;
    }

    public boolean hasFullLava(Block core) {
        if (!isType(core, "LAVA_CAULDRON")) {
            return false;
        }
        return !(core.getBlockData() instanceof Levelled levelled) || levelled.getLevel() == levelled.getMaximumLevel();
    }

    public void openStation(Player player, Block core, StationType station) {
        List<Recipe> recipes = station == StationType.SMELTERY ? smelteryRecipes() : forgeRecipes();
        StationMenuHolder holder = new StationMenuHolder(core.getLocation(), station, recipes);
        Inventory inventory = Bukkit.createInventory(holder, 54, station == StationType.SMELTERY ? "§6Foundry Smeltery" : "§8Foundry Forge");
        holder.setInventory(inventory);
        int[] slots = {10, 12, 14, 16, 28, 30};
        for (int index = 0; index < recipes.size(); index++) {
            Recipe recipe = recipes.get(index);
            ItemStack icon = recipe.output().clone();
            ItemMeta meta = icon.getItemMeta();
            List<String> lore = new ArrayList<>();
            lore.add("§7" + recipe.description());
            lore.add("§8Ingredients: " + recipe.ingredientsText());
            if (station == StationType.SMELTERY) {
                lore.add("§cRequires one full lava cauldron");
            }
            meta.setLore(lore);
            icon.setItemMeta(meta);
            inventory.setItem(slots[index], icon);
        }
        player.openInventory(inventory);
    }

    public void craft(Player player, StationMenuHolder holder, int slot) {
        int[] slots = {10, 12, 14, 16, 28, 30};
        int recipeIndex = -1;
        for (int i = 0; i < slots.length; i++) {
            if (slots[i] == slot) {
                recipeIndex = i;
                break;
            }
        }
        if (recipeIndex < 0 || recipeIndex >= holder.recipes().size()) {
            return;
        }
        Block core = holder.location().getBlock();
        if (holder.station() == StationType.SMELTERY && (!isSmeltery(core) || !hasFullLava(core))) {
            player.sendMessage("§cThe Smeltery needs its complete structure and a full lava cauldron.");
            return;
        }
        if (holder.station() == StationType.FORGE && !isForge(core)) {
            player.sendMessage("§cThe Forge structure is incomplete.");
            return;
        }
        Recipe recipe = holder.recipes().get(recipeIndex);
        if (!hasIngredients(player, recipe.ingredients())) {
            player.sendMessage("§cYou do not have the required ingredients.");
            return;
        }
        removeIngredients(player, recipe.ingredients());
        if (holder.station() == StationType.SMELTERY) {
            core.setType(material("CAULDRON"));
        }
        Map<Integer, ItemStack> overflow = player.getInventory().addItem(recipe.output().clone());
        overflow.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
        player.sendMessage("§aCrafted " + recipe.name() + "!");
    }

    private boolean hasIngredients(Player player, List<Ingredient> ingredients) {
        for (Ingredient ingredient : ingredients) {
            int found = 0;
            for (ItemStack stack : player.getInventory().getStorageContents()) {
                if (matchesIngredient(stack, ingredient)) {
                    found += stack.getAmount();
                }
            }
            if (found < ingredient.amount()) {
                return false;
            }
        }