Add spice cookers and source-built spice-only rails
Some checks failed
DuneRealms Plugin CI / plugins (push) Has been cancelled
Spice Cookers and Rails Build / spice-cookers-rails (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-12-03 22:10:08 +01:00
commit de64f5c6d2
29 changed files with 385 additions and 1 deletions

View file

@ -0,0 +1,53 @@
name: Spice Cookers and Rails Build
on:
workflow_dispatch:
push:
branches: ['feat/spice-cookers-rails-*']
jobs:
spice-cookers-rails:
runs-on: dune-ci
steps:
- name: Check out exact revision
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '9.2.1'
- name: Build tested cookers and patched rails from pinned source
shell: bash
run: |
set -euo pipefail
build="$(mktemp -d)"
mkdir spice-rail-artifacts
git clone --quiet --no-checkout https://github.com/Fridtjof-DE/MinecartTrains.git "$build/rails"
git -C "$build/rails" checkout --detach 2f19054927c96fdf1d025b3e9f6a32c5534aef2a
cmp vendor/minecart-trains/LICENSE.upstream "$build/rails/LICENSE"
git -C "$build/rails" apply "$PWD/vendor/minecart-trains/spice-coal.patch"
curl --fail --location --retry 2 https://cdn.modrinth.com/data/PSN4XhQK/versions/G2YwbBLw/PuddingAPI-2611162255.jar -o "$build/PuddingAPI-2611162255.jar"
(cd "$build" && printf '%s PuddingAPI-2611162255.jar\n' 8c6504f09e6d7b384a4a2651ed33a1b28c7b41a4e42aff89f0e459524697e304 | sha256sum --check)
gradle --no-daemon -p JarvisConnector test jar
gradle --no-daemon -p vendor/minecart-trains jar "-PrailsSource=$build/rails" "-PpuddingJar=$build/PuddingAPI-2611162255.jar"
python3 tools/build-unified-resourcepack.py --source "$GITHUB_SHA" --output "$build/resource-validation.zip"
python3 tools/plugin_spice_cookers.py extract network/resource-pack/central/overlay JarvisConnector/build/libs/jarvistranslator.jar spice-rail-artifacts
cp vendor/minecart-trains/build/libs/MinecartTrains-1.4.3-dune1.jar "$build/PuddingAPI-2611162255.jar" spice-rail-artifacts/
cp vendor/minecart-trains/{build.gradle.kts,settings.gradle.kts,spice-coal.patch} "$build/rails/"
tar -czf spice-rail-artifacts/MinecartTrains-1.4.3-dune1-source.tar.gz -C "$build/rails" LICENSE README.md pom.xml build.gradle.kts settings.gradle.kts spice-coal.patch src
cp tools/{plugin_spice_cookers,plugin_wild_update}.py spice-rail-artifacts/
printf '%s\n' "$(git rev-parse HEAD)" > spice-rail-artifacts/SOURCE_COMMIT
(cd spice-rail-artifacts && sha256sum -- *.zip *.tar.gz *.jar *.py SOURCE_COMMIT > SHA256SUMS)
- uses: actions/upload-artifact@v3
with:
name: DuneRealms-Spice-Cookers-Rails
path: spice-rail-artifacts/
if-no-files-found: error

View file

@ -0,0 +1,10 @@
package com.dunerealms.jarvis;
/** Cook-time arithmetic for spice-infused cookers (kept free of Bukkit types so it can be unit tested). */
final class CookSpeed {
private CookSpeed(){}
/** Vanilla total cook time -> the time at double speed; never below one tick. */
/** Burn ticks that smelt exactly {@code items} items, given the vanilla cook time of the cooker and whether it is infused (double speed). */
static int burnTicks(int vanillaCook,boolean infused,int items){return Math.min(32767,Math.max(1,(infused?doubled(vanillaCook):vanillaCook)*items));}
static int doubled(int vanillaTotal){return Math.max(1,vanillaTotal/2);}
}

View file

@ -27,6 +27,7 @@ final class QuestObservations implements Listener,AutoCloseable {
Bukkit.getPluginManager().registerEvents(this,plugin);
new QuestLoginSettle(plugin,api);
Bukkit.getPluginManager().registerEvents(new ItemOriginRemainders(),plugin);
if(plugin instanceof JarvisTranslator translator)new SpiceFurnaces(plugin,translator::markCreatedItem);
worker.scheduleWithFixedDelay(this::drain,1,5,TimeUnit.SECONDS);
Bukkit.getScheduler().runTaskTimer(plugin,()->{for(var p:Bukkit.getOnlinePlayers())sample(p);},20L,20L);
}

View file

@ -0,0 +1,172 @@
package com.dunerealms.jarvis;
import java.util.*;
import java.util.function.Consumer;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.TileState;
import org.bukkit.event.*;
import org.bukkit.event.block.*;
import org.bukkit.event.inventory.*;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.inventory.*;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.*;
/** Spice-infused furnace, smoker, blast furnace, campfire and soul campfire: same behaviour as vanilla, but every smelt takes half the time. */
final class SpiceFurnaces implements Listener {
/** Vanilla block -> custom item id. */
static final Map<Material,String> IDS=Map.of(Material.FURNACE,"spice_furnace",Material.SMOKER,"spice_smoker",Material.BLAST_FURNACE,"spice_blast_furnace",Material.CAMPFIRE,"spice_campfire",Material.SOUL_CAMPFIRE,"spice_soul_campfire");
static final NamespacedKey MARK=new NamespacedKey("dunerealms","spice_infused_cooker");
private static final NamespacedKey EI=new NamespacedKey("executableitems","ei-id");
static final String COAL_ID="spice_coal";
static final int COAL_ITEMS=50;
static final NamespacedKey COAL_RECIPE=new NamespacedKey("dunerealms","spice_coal");
private final Consumer<ItemStack> stamp;
SpiceFurnaces(Plugin plugin,Consumer<ItemStack> stamp){this.stamp=stamp;Bukkit.getPluginManager().registerEvents(this,plugin);}
static String name(Material type){return switch(type){case SMOKER->"Spice-Infused Smoker";case BLAST_FURNACE->"Spice-Infused Blast Furnace";case CAMPFIRE->"Spice-Infused Campfire";case SOUL_CAMPFIRE->"Spice-Infused Soul Campfire";default->"Spice-Infused Furnace";};}
static NamespacedKey key(Material type){return new NamespacedKey("dunerealms","spice_cooker_"+type.name().toLowerCase(Locale.ROOT));}
/** True when the item is one of ours (and not an owner preview). */
static boolean ours(ItemStack item){
if(item==null||item.isEmpty()||!item.hasItemMeta())return false;
var d=item.getItemMeta().getPersistentDataContainer();
return !d.has(new NamespacedKey("dunerealms","preview_only"))&&IDS.get(item.getType())!=null&&IDS.get(item.getType()).equals(d.get(EI,PersistentDataType.STRING));
}
ItemStack build(Material type,String origin){
var item=new ItemStack(type);var m=item.getItemMeta();String id=IDS.get(type);
m.displayName(Component.text(name(type),NamedTextColor.GOLD).decoration(TextDecoration.ITALIC,false));
m.lore(List.of(Component.text("Smelts at double speed.",NamedTextColor.GRAY).decoration(TextDecoration.ITALIC,false),
Component.text("Infused with raw spice.",NamedTextColor.GRAY).decoration(TextDecoration.ITALIC,false)));
m.setItemModel(new NamespacedKey("dunerealms","crafting/"+id));
var d=m.getPersistentDataContainer();d.set(EI,PersistentDataType.STRING,id);
item.setItemMeta(m);ItemOrigin.created(item,origin);stamp.accept(item);return item;
}
private static boolean marked(BlockState state){return state instanceof TileState tile&&tile.getPersistentDataContainer().has(MARK,PersistentDataType.BYTE);}
// Recipe: iron in the corners, raw spice on the four sides, the vanilla cooker in the middle.
@EventHandler public void loaded(ServerLoadEvent e){
for(Material type:IDS.keySet()){
Bukkit.removeRecipe(key(type));
var recipe=new ShapedRecipe(key(type),build(type,null));recipe.shape("isi","sXs","isi");
recipe.setIngredient('i',Material.IRON_INGOT);recipe.setIngredient('s',Material.ORANGE_DYE);recipe.setIngredient('X',type);
Bukkit.addRecipe(recipe);
}
Bukkit.removeRecipe(COAL_RECIPE);
var coal=new ShapelessRecipe(COAL_RECIPE,buildCoal());
coal.addIngredient(Material.ORANGE_DYE);coal.addIngredient(new RecipeChoice.MaterialChoice(Material.COAL,Material.CHARCOAL));
Bukkit.addRecipe(coal);
}
private static Material target(Recipe recipe){
if(!(recipe instanceof Keyed k)||!"dunerealms".equals(k.getKey().getNamespace()))return null;
for(Material type:IDS.keySet())if(key(type).equals(k.getKey()))return type;
return null;
}
/** Only genuine raw spice (not any orange dye) may fill the four side slots. */
static boolean spiceSlots(ItemStack[] matrix){
if(matrix==null||matrix.length!=9)return false;
if(!ordinary(matrix[4]))return false;
for(int slot:new int[]{1,3,5,7})if(!ExchangeInventory.rawSpice(matrix[slot]))return false;
return true;
}
@EventHandler(priority=EventPriority.HIGHEST) public void prepare(PrepareItemCraftEvent e){
Material type=target(e.getRecipe());if(type==null)return;
if(!spiceSlots(e.getInventory().getMatrix()))e.getInventory().setResult(null);
}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void craft(CraftItemEvent e){
if(target(e.getRecipe())!=null&&!spiceSlots(e.getInventory().getMatrix()))e.setCancelled(true);
}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void crafter(CrafterCraftEvent e){
if(target(e.getRecipe())==null)return;
var inventory=e.getBlock().getState() instanceof org.bukkit.block.Crafter c?c.getInventory().getContents():null;
if(!spiceSlots(inventory))e.setCancelled(true);
}
static boolean spiceCoal(ItemStack item){
if(item==null||item.isEmpty()||item.getType()!=Material.COAL||!item.hasItemMeta())return false;
var d=item.getItemMeta().getPersistentDataContainer();
return !d.has(new NamespacedKey("dunerealms","preview_only"))&&COAL_ID.equals(d.get(EI,PersistentDataType.STRING));
}
ItemStack buildCoal(){
var item=new ItemStack(Material.COAL);var m=item.getItemMeta();
m.displayName(Component.text("Spice Coal",NamedTextColor.GOLD).decoration(TextDecoration.ITALIC,false));
m.lore(List.of(Component.text("Smelts "+COAL_ITEMS+" items in any furnace, smoker or blast furnace.",NamedTextColor.GRAY).decoration(TextDecoration.ITALIC,false),
Component.text("Coal pressed with raw spice.",NamedTextColor.GRAY).decoration(TextDecoration.ITALIC,false)));
m.setItemModel(new NamespacedKey("dunerealms","crafting/"+COAL_ID));
m.getPersistentDataContainer().set(EI,PersistentDataType.STRING,COAL_ID);
item.setItemMeta(m);stamp.accept(item);return item;
}
private static boolean ordinary(ItemStack item){
if(item==null||item.isEmpty())return false;
if(!item.hasItemMeta())return true;
var data=item.getItemMeta().getPersistentDataContainer();
return !data.has(EI)&&!data.has(new NamespacedKey("dunerealms","item"))
&&!data.has(new NamespacedKey("dunerealms","preview_only"));
}
/** One raw spice and one coal (or charcoal) press into one spice coal. */
static boolean coalIngredients(ItemStack[] matrix){
if(matrix==null)return false;int spice=0,coal=0,other=0;
for(var item:matrix){
if(item==null||item.isEmpty())continue;
if(ExchangeInventory.rawSpice(item))spice+=item.getAmount()>0?1:0;
else if((item.getType()==Material.COAL||item.getType()==Material.CHARCOAL)&&ordinary(item))coal++;
else other++;
}
return spice==1&&coal==1&&other==0;
}
@EventHandler(priority=EventPriority.HIGHEST) public void prepareCoal(PrepareItemCraftEvent e){
if(e.getRecipe() instanceof Keyed k&&COAL_RECIPE.equals(k.getKey())&&!coalIngredients(e.getInventory().getMatrix()))e.getInventory().setResult(null);
}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void craftCoal(CraftItemEvent e){
if(e.getRecipe() instanceof Keyed k&&COAL_RECIPE.equals(k.getKey())&&!coalIngredients(e.getInventory().getMatrix()))e.setCancelled(true);
}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void crafterCoal(CrafterCraftEvent e){
if(!(e.getRecipe() instanceof Keyed k)||!COAL_RECIPE.equals(k.getKey()))return;
var inventory=e.getBlock().getState() instanceof org.bukkit.block.Crafter c?c.getInventory().getContents():null;
if(!coalIngredients(inventory))e.setCancelled(true);
}
/** Spice coal burns for exactly {@link #COAL_ITEMS} smelts in whichever cooker it is loaded into. */
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void fuel(FurnaceBurnEvent e){
if(!spiceCoal(e.getFuel()))return;
int base=e.getBlock().getType()==Material.FURNACE?200:100;
e.setBurnTime(CookSpeed.burnTicks(base,marked(e.getBlock().getState()),COAL_ITEMS));
}
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public void placed(BlockPlaceEvent e){
if(!ours(e.getItemInHand())||!(e.getBlockPlaced().getState() instanceof TileState tile))return;
var data=tile.getPersistentDataContainer();
data.set(MARK,PersistentDataType.BYTE,(byte)1);
String origin=e.getItemInHand().getItemMeta().getPersistentDataContainer().get(ItemOrigin.WORLD,PersistentDataType.STRING);
if(origin!=null&&ItemOrigin.label(origin)!=null)data.set(ItemOrigin.WORLD,PersistentDataType.STRING,origin);
tile.update();
}
/** Pick it up as the infused item again, keeping the marker out of vanilla furnaces. */
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void drops(BlockDropItemEvent e){
if(!marked(e.getBlockState()))return;
Material type=e.getBlockState().getType();if(!IDS.containsKey(type))return;
var data=((TileState)e.getBlockState()).getPersistentDataContainer();
String origin=data.get(ItemOrigin.WORLD,PersistentDataType.STRING);
for(var drop:e.getItems()){
var stack=drop.getItemStack();
boolean ash=type==Material.CAMPFIRE&&stack.getType()==Material.CHARCOAL
||type==Material.SOUL_CAMPFIRE&&stack.getType()==Material.SOUL_SOIL;
if(!ash&&(stack.getType()!=type||ours(stack)))continue;
var result=build(type,origin);
drop.setItemStack(result);
break;
}
}
/** Every smelt starts with half the vanilla cook time. */
@EventHandler(priority=EventPriority.HIGH,ignoreCancelled=true) public void start(FurnaceStartSmeltEvent e){
if(marked(e.getBlock().getState()))e.setTotalCookTime(CookSpeed.doubled(e.getTotalCookTime()));
}
@EventHandler(priority=EventPriority.HIGH,ignoreCancelled=true) public void campfire(CampfireStartEvent e){
if(marked(e.getBlock().getState()))e.setTotalCookTime(CookSpeed.doubled(e.getTotalCookTime()));
}
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public void burn(FurnaceBurnEvent e){
Block b=e.getBlock();if(!marked(b.getState()))return;
b.getWorld().spawnParticle(Particle.FLAME,b.getLocation().add(.5,1.05,.5),6,.2,.05,.2,.01);
}
}

View file

@ -1454,6 +1454,48 @@
"material": "DRIED_KELP_BLOCK",
"policy": "s1-item-metadata-v1"
},
"spice_furnace": {
"itemClass": "resource",
"quality": "rare",
"equipmentMark": 3,
"material": "FURNACE",
"policy": "s1-item-metadata-v1"
},
"spice_smoker": {
"itemClass": "resource",
"quality": "rare",
"equipmentMark": 3,
"material": "SMOKER",
"policy": "s1-item-metadata-v1"
},
"spice_blast_furnace": {
"itemClass": "resource",
"quality": "rare",
"equipmentMark": 3,
"material": "BLAST_FURNACE",
"policy": "s1-item-metadata-v1"
},
"spice_campfire": {
"itemClass": "resource",
"quality": "rare",
"equipmentMark": 3,
"material": "CAMPFIRE",
"policy": "s1-item-metadata-v1"
},
"spice_soul_campfire": {
"itemClass": "resource",
"quality": "rare",
"equipmentMark": 3,
"material": "SOUL_CAMPFIRE",
"policy": "s1-item-metadata-v1"
},
"spice_coal": {
"itemClass": "resource",
"quality": "rare",
"equipmentMark": 3,
"material": "COAL",
"policy": "s1-item-metadata-v1"
},
"smuggled_spice_block": {
"itemClass": "resource",
"quality": "uncommon",

View file

@ -0,0 +1,15 @@
package com.dunerealms.jarvis;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class CookSpeedTest {
@Test void halvesVanillaCookTimes(){assertEquals(100,CookSpeed.doubled(200));assertEquals(50,CookSpeed.doubled(100));assertEquals(300,CookSpeed.doubled(600));}
@Test void neverBelowOneTick(){assertEquals(1,CookSpeed.doubled(1));assertEquals(1,CookSpeed.doubled(0));assertEquals(1,CookSpeed.doubled(-5));}
@Test void oddTimesRoundDown(){assertEquals(2,CookSpeed.doubled(5));}
@Test void spiceCoalSmeltsFiftyItemsInEveryCooker(){
assertEquals(10000,CookSpeed.burnTicks(200,false,50));assertEquals(5000,CookSpeed.burnTicks(100,false,50));
assertEquals(5000,CookSpeed.burnTicks(200,true,50));assertEquals(2500,CookSpeed.burnTicks(100,true,50));
}
@Test void burnTimeFitsTheShortLimitOfTheEvent(){assertEquals(32767,CookSpeed.burnTicks(200,false,500));}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

Some files were not shown because too many files have changed in this diff Show more