Issue Crysknife and Maker tooth through JARVIS
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-11-29 22:53:22 +01:00
commit 2cb4778774
16 changed files with 253 additions and 9 deletions

View file

@ -8,7 +8,7 @@ DuneRealms terrain runs on Java 21. Build with `gradle build`; install `build/li
- **Dense Spice** (`dunerealms:dense-spice`): one 30 × 30 rich patch per 512-block placement region, with seed-dependent positions. This is configurable village-like density, not vanilla village placement. Deep orange terracotta represents finite rich spice sand. Each authentic deposit yields four existing tagged Melange Spice items by default. Silk Touch and Fortune cannot clone or multiply it; creative mining consumes the deposit without a reward. A chunk Persistent Data Container stores each deposit's position and removes it on harvest. Ordinary orange terracotta has no spice value. Pistons and explosions cannot move or duplicate registered deposits. Ledger state persists in normal chunk saves across restarts; restoring a world backup restores its historical deposits too.
- A persistent spice seller appears in the centre of each new rich field. Right-click opens the shared native menu and offers 16 tagged spice at **standard DuneEss price × 1.35**. At 15 Solaris each, 16 cost 324 Solaris. Existing spice sales, taxes and CHOAM trading remain unchanged. Confirming purchases checks distance, inventory capacity and successful economy withdrawal.
- **Desert villages**: custom four-house sandstone settlements, with cut-sandstone lanes, villagers, beds, non-farming workstations, lanterns and finite shared supply chests. No farmland, crops or hay bales enter the structure palette. Chests use `dunerealms:chests/desert-village`: bread, dried kelp, apples and raw iron. Placement regions default to 768 blocks, with terrain suitability checks.
- **Harkonnen garrison fortress** (pillager-outpost mechanic): a walled black-stone fortress with four searchlight towers, a three-storey keep (barracks, armoury, command room, roof), a landing pad, a cell block, a supply depot and a vault under the keep. Placement copies the vanilla pillager outpost: one attempt per 32x32-chunk region, 8 chunks of separation, 20% frequency (`harkonnen-fortress.spacing-chunks|separation-chunks|frequency`). Harkonnen pillagers (8 guards plus a commander, black dyed armour, no bad-omen banner) are spawned when a player comes near and replaced after `respawn-seconds`. The vault chest is filled on first open with one Harkonnen stillsuit piece plus 3 random valuables (Maker's Tooth when supported by DuneCore, refined spice, spice block, smuggler shovel, etc.; override with `harkonnen-fortress.loot`). Chests from the old temple-style fortress keep their loot rules.
- **Harkonnen garrison fortress** (pillager-outpost mechanic): a walled black-stone fortress with four searchlight towers, a three-storey keep (barracks, armoury, command room, roof), a landing pad, a cell block, a supply depot and a vault under the keep. Placement copies the vanilla pillager outpost: one attempt per 32x32-chunk region, 8 chunks of separation, 20% frequency (`harkonnen-fortress.spacing-chunks|separation-chunks|frequency`). Harkonnen pillagers (8 guards plus a commander, black dyed armour, no bad-omen banner) are spawned when a player comes near and replaced after `respawn-seconds`. The vault chest is filled on first open with one Harkonnen stillsuit piece plus 3 random valuables (Maker's Tooth issued by J.A.R.V.I.S., refined spice, spice block, smuggler shovel, etc.; override with `harkonnen-fortress.loot`). Chests from the old temple-style fortress keep their loot rules.
- **Abandoned Fremen village**: always generated beside a Harkonnen outpost (one of eight fixed offsets chosen from the outpost id): a dry cistern, broken windtrap, six sand-drifted sandstone and terracotta houses with faded Fremen-blue cloth, dry qanat channels and two caches. No villagers, no farmland.
Arrakis generates small, medium, and large sietches on separate grids with default spacing of 600, 900, and 2,000 blocks. Larger tiers take priority when footprints overlap. Each tier has independent `enabled` and `spacing` settings under `sietches`. Placement applies as chunks generate.

View file

@ -1,7 +1,7 @@
plugins { java }
group = "com.example"
version = "1.0.17-structures1"
version = "1.0.18-jarvisloot1"
repositories {
mavenCentral()

View file

@ -74,9 +74,11 @@ final class StructureCaches implements Listener {
switch (e.source()) {
case "ei": { ItemStack i = ArrakisEcology.item(e.id()); i.setAmount(Math.min(i.getMaxStackSize(), p.amount())); return i; }
case "tooth": {
var core = Bukkit.getPluginManager().getPlugin("DuneCore");
if (core == null || !core.isEnabled()) return null;
ItemStack i = (ItemStack) core.getClass().getMethod("createMakerTooth").invoke(core); i.setAmount(p.amount()); return i;
var jarvis = Bukkit.getPluginManager().getPlugin("JarvisTranslator");
if (jarvis == null || !jarvis.isEnabled()) return null;
ItemStack i = (ItemStack) jarvis.getClass().getMethod("issueMakerTooth").invoke(jarvis);
if (i != null) i.setAmount(Math.min(i.getMaxStackSize(), p.amount()));
return i;
}
case "kit-shovel": for (ItemStack i : coreKit("Harkonnen")) if (i.getType() == Material.NETHERITE_SHOVEL) return i; return null;
default: { Material m = Material.matchMaterial(e.id()); return m == null ? null : new ItemStack(m, Math.min(m.getMaxStackSize(), p.amount())); }

View file

@ -1,5 +1,5 @@
name: DuneTerrain
version: 1.0.17-structures1
version: 1.0.18-jarvisloot1
main: com.example.duneterrain.DuneTerrain
api-version: '1.21'
load: STARTUP

View file

@ -1,6 +1,6 @@
plugins { java }
group = "com.dunerealms"
version = "0.5.36-pillager1"
version = "0.5.37-crysknife1"
repositories { mavenCentral(); maven("https://repo.papermc.io/repository/maven-public/") }
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")

View file

@ -0,0 +1,192 @@
package com.dunerealms.jarvis;
import java.util.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
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.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.block.CrafterCraftEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
/**
* Sandworm kills can drop a Maker's Tooth; a tooth plus Melange Spice is crafted into a crysknife.
* The knife binds to its crafter and crumbles if someone else holds it for a while, so theft is useless.
* Items use the existing {@code dunerealms:item} tag and J.A.R.V.I.S. item metadata.
*/
final class Crysknife implements Listener {
private static final String TOOTH = "maker_tooth", KNIFE = "crysknife";
private final JarvisTranslator plugin;
private final NamespacedKey itemKey = new NamespacedKey("dunerealms", "item");
private final NamespacedKey ownerKey = new NamespacedKey("dunerealms", "crysknife_owner");
private final NamespacedKey recipeKey = new NamespacedKey("dunerealms", "crysknife_recipe");
private final NamespacedKey bodyKey, brainKey;
private final Map<UUID, Long> heldSince = new HashMap<>();
private final Random random = new Random();
private final BukkitTask sweep;
Crysknife(JarvisTranslator plugin) {
this.plugin = plugin;
bodyKey = new NamespacedKey("dunecore", "sandworm_body");
brainKey = new NamespacedKey("dunecore", "sandworm_brain");
var recipe = new ShapelessRecipe(recipeKey, knife(null));
recipe.addIngredient(Material.BONE);
recipe.addIngredient(Material.ORANGE_DYE);
plugin.getServer().addRecipe(recipe);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
sweep = plugin.getServer().getScheduler().runTaskTimer(plugin, this::sweepForeignKnives, 100L, 100L);
}
void close() { sweep.cancel(); plugin.getServer().removeRecipe(recipeKey); }
// ---- items ----
ItemStack tooth() {
var item = new ItemStack(Material.BONE);
ItemMeta meta = item.getItemMeta();
meta.displayName(Component.text("Maker's Tooth", NamedTextColor.WHITE).decoration(TextDecoration.ITALIC, false));
meta.lore(List.of(Component.text("Shed by a dying Shai-Hulud.", NamedTextColor.GRAY),
Component.text("Fremen shape it with spice into a crysknife.", NamedTextColor.DARK_GRAY)));
meta.setItemModel(new NamespacedKey("dunerealms", TOOTH));
meta.getPersistentDataContainer().set(itemKey, PersistentDataType.STRING, TOOTH);
item.setItemMeta(meta);
plugin.markCreatedItem(item);
return item;
}
/** A knife with no owner (placeholder, admin give) never crumbles; crafting stamps the crafter. */
ItemStack knife(UUID owner) {
var item = new ItemStack(Material.IRON_SWORD);
ItemMeta meta = item.getItemMeta();
meta.displayName(Component.text("Crysknife", NamedTextColor.AQUA).decoration(TextDecoration.ITALIC, false));
meta.lore(List.of(Component.text("A milk-white blade, bound to the one who shaped it.", NamedTextColor.GRAY),
Component.text("It crumbles if another keeps it too long.", NamedTextColor.DARK_GRAY)));
meta.setItemModel(new NamespacedKey("dunerealms", KNIFE));
meta.setUnbreakable(true);
meta.addAttributeModifier(Attribute.ATTACK_DAMAGE, new AttributeModifier(new NamespacedKey("dunerealms", "crysknife_damage"),
plugin.getConfig().getDouble("crysknife.attack-bonus", 4.0), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
meta.addAttributeModifier(Attribute.ATTACK_SPEED, new AttributeModifier(new NamespacedKey("dunerealms", "crysknife_speed"),
-1.8, AttributeModifier.Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND));
var data = meta.getPersistentDataContainer();
data.set(itemKey, PersistentDataType.STRING, KNIFE);
if (owner != null) data.set(ownerKey, PersistentDataType.STRING, owner.toString());
item.setItemMeta(meta);
if (owner != null) plugin.markCreatedItem(item);
return item;
}
private String tag(ItemStack item) {
if (item == null || !item.hasItemMeta()) return null;
var data = item.getItemMeta().getPersistentDataContainer();
if (data.has(new NamespacedKey("dunerealms", "preview_only"))) return null;
return data.get(itemKey, PersistentDataType.STRING);
}
private boolean isKnife(ItemStack item) { return KNIFE.equals(tag(item)); }
private UUID ownerOf(ItemStack item) {
String raw = item.getItemMeta().getPersistentDataContainer().get(ownerKey, PersistentDataType.STRING);
try { return raw == null ? null : UUID.fromString(raw); } catch (IllegalArgumentException invalid) { return null; }
}
private boolean isWorm(Entity e) {
if (!e.getWorld().getName().equalsIgnoreCase("arrakis")) return false;
var data = e.getPersistentDataContainer();
String partner = data.get(e instanceof org.bukkit.entity.Sniffer ? brainKey : bodyKey, PersistentDataType.STRING);
return (e instanceof org.bukkit.entity.Sniffer || e instanceof org.bukkit.entity.Husk)
&& partner != null && !partner.equals("pending");
}
// ---- tooth drop ----
/** Runs after SandwormMobs has cleared the worm's drops. */
@EventHandler(priority = EventPriority.HIGH)
public void onWormDeath(EntityDeathEvent event) {
if (!isWorm(event.getEntity())) return;
if (CrysknifeRules.toothDrops(random.nextDouble(), plugin.getConfig().getDouble("crysknife.tooth-chance", 0.15)))
event.getDrops().add(tooth());
}
// ---- crafting: one Maker's Tooth and one Melange Spice, nothing else ----
private boolean isRecipe(Recipe recipe) {
return recipe instanceof ShapelessRecipe shapeless && recipeKey.equals(shapeless.getKey());
}
private boolean ingredients(ItemStack[] matrix) {
boolean tooth = false, spice = false;
for (ItemStack ingredient : matrix) {
if (ingredient == null || ingredient.getType().isAir()) continue;
if (!tooth && ingredient.getType() == Material.BONE && TOOTH.equals(tag(ingredient))) tooth = true;
else if (!spice && ExchangeInventory.saleSpice(ingredient, "guild")) spice = true;
else return false;
}
return tooth && spice;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPrepare(PrepareItemCraftEvent event) {
if (!isRecipe(event.getRecipe())) return;
event.getInventory().setResult(ingredients(event.getInventory().getMatrix())
? knife(event.getView().getPlayer().getUniqueId()) : null);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCraft(CraftItemEvent event) {
if (isRecipe(event.getRecipe()) && (!ingredients(event.getInventory().getMatrix())
|| !event.getWhoClicked().getUniqueId().equals(ownerOfResult(event.getCurrentItem())))) event.setCancelled(true);
}
private UUID ownerOfResult(ItemStack item) {
return isKnife(item) ? ownerOf(item) : null;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCrafter(CrafterCraftEvent event) {
if (isRecipe(event.getRecipe())) event.setCancelled(true);
}
// ---- worm bonus ----
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onHit(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player player) || !isWorm(event.getEntity())) return;
ItemStack held = player.getInventory().getItemInMainHand();
if (!isKnife(held)) return;
event.setDamage(CrysknifeRules.wormDamage(event.getDamage(), plugin.getConfig().getDouble("crysknife.worm-damage-multiplier", 1.5)));
}
// ---- binding: foreign knives crumble ----
private void sweepForeignKnives() {
long now = System.currentTimeMillis(), grace = plugin.getConfig().getLong("crysknife.crumble-seconds", 180) * 1000L;
for (Player player : plugin.getServer().getOnlinePlayers()) {
boolean foreign = false;
ItemStack[] contents = player.getInventory().getContents();
for (int i = 0; i < contents.length; i++) {
ItemStack item = contents[i];
if (!isKnife(item)) continue;
UUID owner = ownerOf(item);
if (owner == null || owner.equals(player.getUniqueId())) continue;
foreign = true;
if (CrysknifeRules.crumbleDue(heldSince.get(player.getUniqueId()), now, grace)) {
player.getInventory().setItem(i, null);
player.sendMessage(Component.text("The crysknife crumbles to dust in hands that did not shape it.", NamedTextColor.GRAY));
}
}
if (foreign) heldSince.putIfAbsent(player.getUniqueId(), now); else heldSince.remove(player.getUniqueId());
}
}
@EventHandler public void onQuit(PlayerQuitEvent event) { heldSince.remove(event.getPlayer().getUniqueId()); }
}

View file

@ -0,0 +1,17 @@
package com.dunerealms.jarvis;
/** Pure crysknife rules, kept free of Bukkit types so they can be unit-tested. */
final class CrysknifeRules {
private CrysknifeRules() {}
/** A random roll in [0,1) beats the configured chance. A chance of 0 or less never drops. */
static boolean toothDrops(double roll, double chance) { return chance > 0 && roll < chance; }
/** True once a knife has been held by someone other than its owner for the whole grace period. */
static boolean crumbleDue(Long heldSinceMs, long nowMs, long graceMs) {
return heldSinceMs != null && nowMs - heldSinceMs >= graceMs;
}
/** Worm damage is only ever raised, never reduced, by the configured multiplier. */
static double wormDamage(double base, double multiplier) { return base * Math.max(1.0, multiplier); }
}

View file

@ -42,6 +42,11 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
public void refineSpice(org.bukkit.entity.Player player,JsonObject permit)throws Exception{spiceRefiner.execute(player,permit);}
private ItemMetadataOverlay itemMetadata;
private SpiceBlocks spiceBlocks;
private Crysknife crysknife;
public org.bukkit.inventory.ItemStack issueMakerTooth(){
if(!Bukkit.isPrimaryThread())throw new IllegalStateException("Create items on the server thread");
return crysknife==null?null:crysknife.tooth();
}
public org.bukkit.inventory.ItemStack compressedSpice(org.bukkit.inventory.ItemStack raw){return spiceBlocks.compress(raw);}
public void markCreatedItem(org.bukkit.inventory.ItemStack item){if(!Bukkit.isPrimaryThread())throw new IllegalStateException("Create items on the server thread");ItemOrigin.created(item);itemMetadata.stamp(item);}
public int spiceCount(org.bukkit.entity.Player p){return exchangeInventory.spiceCount(p);}
@ -122,6 +127,7 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
try { itemMetadata=new ItemMetadataOverlay(this);exchangeInventory=new ExchangeInventory(item->itemMetadata.stamp(item),serverKey);itemPreview=new ItemDesignPreview(new ItemMetadataPolicy(getResource("item-templates.json")),new ItemCardArt(getResource("item-card-glyphs.json"))); }
catch (java.io.IOException invalid) { throw new IllegalStateException("Shared item metadata catalogue is unavailable",invalid); }
spiceBlocks=new SpiceBlocks(this,item->itemMetadata.stamp(item));
if ("arrakis".equals(serverKey)) crysknife = new Crysknife(this);
var survivalRecipes=new SurvivalFoodRecipes(this,itemMetadata);
new ArrakisBrewing(this,itemMetadata,survivalRecipes);
new WeirdingModule(this,itemMetadata);
@ -257,6 +263,6 @@ public final class JarvisTranslator extends JavaPlugin implements Listener {
if (!isEnabled()) return CompletableFuture.completedFuture(NativeActions.Result.UNAVAILABLE);
return actions.execute(actor, action, keyReference);
}
@Override public void onDisable() { if(imperialRaids!=null)imperialRaids.close();if(spiceRaiderMining!=null)spiceRaiderMining.close();if(warCampaigns!=null)warCampaigns.close();if(questObservations!=null)questObservations.close();if(nativeKeys!=null)nativeKeys.close();if (actions != null) actions.close(); if (api != null) api.close(); }
@Override public void onDisable() { if(crysknife!=null){crysknife.close();crysknife=null;}if(imperialRaids!=null)imperialRaids.close();if(spiceRaiderMining!=null)spiceRaiderMining.close();if(warCampaigns!=null)warCampaigns.close();if(questObservations!=null)questObservations.close();if(nativeKeys!=null)nativeKeys.close();if (actions != null) actions.close(); if (api != null) api.close(); }
}

View file

@ -1,6 +1,6 @@
name: JarvisTranslator
main: com.dunerealms.jarvis.JarvisTranslator
version: 0.5.36-pillager1
version: 0.5.37-crysknife1
api-version: '1.21.8'
description: Shared J.A.R.V.I.S. website API and native server action translator.
softdepend: [Citizens, Citizens, CoreProtect, SCore, ExecutableItems, ExecutableCrafting, DuneEss, ImageFrame, DecentHolograms, MedievalFactions, Towny, WorldGuard]

View file

@ -0,0 +1,23 @@
package com.dunerealms.jarvis;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class CrysknifeRulesTest {
@Test void toothRollsAgainstTheChance() {
assertTrue(CrysknifeRules.toothDrops(0.10, 0.15));
assertFalse(CrysknifeRules.toothDrops(0.15, 0.15));
assertFalse(CrysknifeRules.toothDrops(0.0, 0.0));
assertFalse(CrysknifeRules.toothDrops(0.0, -1.0));
}
@Test void crumbleNeedsAForeignHoldForTheWholeGracePeriod() {
assertFalse(CrysknifeRules.crumbleDue(null, 1_000, 180_000));
assertFalse(CrysknifeRules.crumbleDue(1_000L, 100_000, 180_000));
assertTrue(CrysknifeRules.crumbleDue(1_000L, 181_000, 180_000));
}
@Test void wormDamageIsNeverReduced() {
assertEquals(15.0, CrysknifeRules.wormDamage(10.0, 1.5), 1e-9);
assertEquals(10.0, CrysknifeRules.wormDamage(10.0, 0.5), 1e-9);
}
}

View file

@ -0,0 +1 @@
{"model":{"type":"minecraft:model","model":"dunerealms:item/crysknife"}}

View file

@ -0,0 +1 @@
{"model":{"type":"minecraft:model","model":"dunerealms:item/maker_tooth"}}

View file

@ -0,0 +1 @@
{"parent":"minecraft:item/handheld","textures":{"layer0":"dunerealms:item/crysknife"}}

View file

@ -0,0 +1 @@
{"parent":"minecraft:item/generated","textures":{"layer0":"dunerealms:item/maker_tooth"}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB