Compare commits

..
Author SHA1 Message Date
unimatrixgit
9e8f23810a Include requested Sigma goats in the ATM update capsule
Some checks failed
ATM RIA Copy and Sigma Goats / atm-ria-copy (push) Successful in 2m38s
DuneRealms Resourcepack CI / resourcepack (push) Has been cancelled
DuneRealms Plugin CI / plugins (push) Has been cancelled
2026-12-05 16:52:06 +01:00
unimatrixgit
986bf4d57e Add private RIA copy actions and prefilled voucher redemption 2026-12-05 16:52:00 +01:00
unimatrixgit
903e21dbe6 Allow goats in Sigma mountain biomes 2026-12-05 16:49:58 +01:00
11 changed files with 246 additions and 6 deletions

View file

@ -0,0 +1,47 @@
name: ATM RIA Copy and Sigma Goats
on:
workflow_dispatch:
push:
branches: ['fix/atm-ria-copy-*']
jobs:
atm-ria-copy:
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: Test ATM controls and preserve Sigma ecology
shell: bash
run: |
set -euo pipefail
gradle --no-daemon -p DuneMenus test jar
gradle --no-daemon -p DuneTerrain test jar
mkdir atm-ria-copy
PYTHONPATH=tools python3 - <<'PY'
from pathlib import Path
from plugin_ria_copy import ATM, COPY
from plugin_wild_update import read_archive, write_archive
compiled=read_archive(Path('DuneMenus/build/libs/DuneMenus.jar').read_bytes())
Path('atm-ria-copy/donor.zip').write_bytes(write_archive({p:compiled[p] for p in (ATM,COPY)}))
PY
cp tools/{plugin_ria_copy.py,plugin_wild_update.py,plugin_sigma_goats.py,SigmaGoatMerge.java} atm-ria-copy/
printf '%s\n' "$GITHUB_SHA" > atm-ria-copy/SOURCE_COMMIT
(cd atm-ria-copy && sha256sum -- *.zip *.py *.java SOURCE_COMMIT > SHA256SUMS)
- uses: actions/upload-artifact@v3
with:
name: DuneRealms-ATM-RIA-Copy-Sigma-Goats
path: atm-ria-copy
if-no-files-found: error

View file

@ -25,6 +25,7 @@ final class AtmMenu extends Menu {
private String entered; // RIA ID typed on the Redeem tab
private String receiptOperation,receiptReference,receiptMessage;
private Long receiptAmount;
private boolean receiptCanRedeem;
AtmMenu(DuneMenusPlugin plugin, Player p, Menu parent, Tab tab) { super(plugin, p, parent); this.tab = tab; }
String id() { return switch(tab){case WITHDRAW->"withdraw";case DEPOSIT->"deposit";case REDEEM->"redeem";case RECEIPT->"receipt";default->"atm";}; }
@ -67,7 +68,12 @@ final class AtmMenu extends Menu {
if(tab==Tab.RECEIPT){
put(13,Ui.item(Material.PAPER,"<gold>"+receiptOperation,
receiptAmount==null?"<gray>"+receiptMessage:"<gray>Amount: <white>"+Ui.dm(receiptAmount),"<gray>"+receiptMessage));
if(receiptReference!=null&&!receiptReference.isBlank())put(29,Ui.item(Material.NAME_TAG,"<gold>RIA ID","<white>"+receiptReference));
String reference=RiaReference.normalize(receiptReference);
if(reference!=null){
referenceButton(reference);
if(receiptCanRedeem)put(31,Ui.item(Material.ENDER_CHEST,"<aqua>Use this RIA ID",
"<gray>Open its payout options","<gray>No need to type the reference"),c->{entered=reference;tab=Tab.REDEEM;redraw();});
}
return;
}
if (tab == Tab.REDEEM) drawRedeem(); else drawCash();
@ -106,7 +112,19 @@ final class AtmMenu extends Menu {
private void receipt(String operation,Backend.CashReceipt facts,String message){
receiptOperation=facts!=null&&facts.recovered()?"Recovered Rihla transaction":operation;
receiptAmount=facts==null?null:facts.amountMinor();receiptReference=facts==null?null:facts.riaId();receiptMessage=message;
receiptCanRedeem="Cash deposit".equals(operation)&&RiaReference.normalize(receiptReference)!=null;
selected.clear();tab=Tab.RECEIPT;redraw();
if(RiaReference.normalize(receiptReference)!=null)player.sendMessage(RiaClipboard.message(receiptReference));
}
private void referenceButton(String reference){
boolean bedrock=plugin.modeFor(player)==Mode.BEDROCK;
put(29,Ui.item(Material.NAME_TAG,bedrock?"<gold>Show RIA ID in chat":"<gold>Copy RIA ID",
"<white>"+reference,bedrock?"<gray>Send the reference privately to chat":"<gray>Open a private click-to-copy link"),c->{
end();plugin.closeNativePresentation(player);
if(!bedrock)player.sendMessage(net.kyori.adventure.text.Component.text("Press T, then click the RIA ID below to copy it."));
player.sendMessage(RiaClipboard.message(reference));
});
}
private void drawRedeem() {
@ -118,7 +136,7 @@ final class AtmMenu extends Menu {
});
for (int s : new int[]{28, 30}) put(s, Ui.pane(Material.YELLOW_STAINED_GLASS_PANE));
if (entered == null) return;
put(29,Ui.item(Material.NAME_TAG,"<gold>RIA ID","<white>"+entered));
referenceButton(entered);
final String id = entered;
load(backend().atmLookup(player, id), v -> {
if (v == null) { put(22, Ui.item(Material.BARRIER, "<red>RIA ID not found")); return; }

View file

@ -0,0 +1,20 @@
package com.dunerealms.menus;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
/** A private native-client copy action; never submits or redeems a voucher. */
final class RiaClipboard {
private RiaClipboard() {}
static Component message(String reference) {
String complete=RiaReference.normalize(reference);
if(complete==null)throw new IllegalArgumentException("A complete RIA reference is required");
return Component.text("RIA ID: ",NamedTextColor.GOLD)
.append(Component.text(complete,NamedTextColor.AQUA))
.clickEvent(ClickEvent.copyToClipboard(complete))
.hoverEvent(HoverEvent.showText(Component.text("Click to copy the complete RIA ID")));
}
}

View file

@ -0,0 +1,20 @@
package com.dunerealms.menus;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class RiaClipboardTest {
@Test void copiesTheCompleteReferenceWithoutSubmittingAnyCommand(){
String id="RIA-0123456789ABCDEF0123456789ABCDEF";
var message=RiaClipboard.message(" "+id.toLowerCase(java.util.Locale.ROOT)+" ");
assertEquals(ClickEvent.Action.COPY_TO_CLIPBOARD,message.clickEvent().action());
assertEquals(id,message.clickEvent().value());
assertTrue(PlainTextComponentSerializer.plainText().serialize(message).contains(id));
}
@Test void incompleteOrForeignReferencesCannotBecomeCopyActions(){
for(String invalid:new String[]{null,"","RIA-1234","ITM-0123456789ABCDEF0123456789ABCDEF"})
assertThrows(IllegalArgumentException.class,()->RiaClipboard.message(invalid));
}
}

View file

@ -74,7 +74,14 @@
"spawners": {
"ambient": [],
"axolotls": [],
"creature": [],
"creature": [
{
"type": "minecraft:goat",
"weight": 5,
"minCount": 1,
"maxCount": 3
}
],
"misc": [],
"monster": [
{

View file

@ -74,7 +74,14 @@
"spawners": {
"ambient": [],
"axolotls": [],
"creature": [],
"creature": [
{
"type": "minecraft:goat",
"weight": 5,
"minCount": 1,
"maxCount": 3
}
],
"misc": [],
"monster": [
{

View file

@ -74,7 +74,14 @@
"spawners": {
"ambient": [],
"axolotls": [],
"creature": [],
"creature": [
{
"type": "minecraft:goat",
"weight": 5,
"minCount": 1,
"maxCount": 3
}
],
"misc": [],
"monster": [
{

View file

@ -10,7 +10,7 @@ import org.bukkit.plugin.Plugin;
public final class PlanetMobs implements Listener {
private static final Set<String> NETHER=Set.of("BLAZE","GHAST","HOGLIN","MAGMA_CUBE","PIGLIN","PIGLIN_BRUTE","STRIDER","WITHER_SKELETON","ZOGLIN","ZOMBIFIED_PIGLIN","SKELETON","ENDERMAN");
private static final Set<String> PASSIVE=Set.of("ALLAY","ARMADILLO","AXOLOTL","BAT","CAMEL","CAT","CHICKEN","COD","COW","DONKEY","FROG","GLOW_SQUID","HORSE","MUSHROOM_COW","MOOSHROOM","MULE","OCELOT","PARROT","PIG","PUFFERFISH","RABBIT","SALMON","SHEEP","SNIFFER","SNOWMAN","SNOW_GOLEM","SQUID","STRIDER","TADPOLE","TROPICAL_FISH","TURTLE","VILLAGER","WANDERING_TRADER");
public static boolean allowed(String planet,String mob,boolean island){if(allowedColdPig(planet,mob))return true;return switch(planet){case "caladan"->!mob.equals("CREEPER");case "kaitain"->PASSIVE.contains(mob);case "giedi_prime"->NETHER.contains(mob);case "sigma_draconis_iv"->Set.of("SKELETON","STRAY","WITHER_SKELETON","BOGGED").contains(mob)||island&&Set.of("MUSHROOM_COW","MOOSHROOM","SULFUR_CUBE").contains(mob);default->true;};}
public static boolean allowed(String planet,String mob,boolean island){if("sigma_draconis_iv".equals(planet)&&"GOAT".equals(mob)||allowedColdPig(planet,mob))return true;return switch(planet){case "caladan"->!mob.equals("CREEPER");case "kaitain"->PASSIVE.contains(mob);case "giedi_prime"->NETHER.contains(mob);case "sigma_draconis_iv"->Set.of("SKELETON","STRAY","WITHER_SKELETON","BOGGED").contains(mob)||island&&Set.of("MUSHROOM_COW","MOOSHROOM","SULFUR_CUBE").contains(mob);default->true;};}
public static boolean allowedSpawn(String planet,String mob,boolean island,String reason){return allowed(planet,mob,island)||planet.equals("giedi_prime")&&(reason.equals("SPAWNER")&&Set.of("SKELETON","ZOMBIE","SPIDER","CAVE_SPIDER").contains(mob)||mob.equals("WARDEN"));}
public static void start(Plugin plugin){Bukkit.getPluginManager().registerEvents(new PlanetMobs(),plugin);Bukkit.getPluginManager().registerEvents(new NativePlants(),plugin);PlanetSoil.start(plugin);}
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void spawning(CreatureSpawnEvent event){if(sigmaColdPig(event))return;var e=event.getEntity();String planet=e.getWorld().getName();if(!TemperateLandscape.enabled(planet))return;

40
tools/SigmaGoatMerge.java Normal file
View file

@ -0,0 +1,40 @@
import java.nio.file.Files;
import java.nio.file.Path;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
class SigmaGoatMerge {
public static void main(String[] args) throws Exception {
var reader = new ClassReader(Files.readAllBytes(Path.of(args[0])));
var retained = new ClassNode();
reader.accept(retained, 0);
if (!retained.name.equals("com/example/duneterrain/PlanetMobs")
|| retained.methods.stream().noneMatch(m -> m.name.equals("allowedColdPig"))) {
throw new IllegalArgumentException("Expected the retained Sigma cold-pig baseline");
}
var allowed = retained.methods.stream()
.filter(m -> m.name.equals("allowed") && m.desc.equals("(Ljava/lang/String;Ljava/lang/String;Z)Z"))
.findFirst().orElseThrow();
var resume = new LabelNode();
var patch = new InsnList();
match(patch, "sigma_draconis_iv", 0, resume);
match(patch, "GOAT", 1, resume);
patch.add(new InsnNode(Opcodes.ICONST_1));
patch.add(new InsnNode(Opcodes.IRETURN));
patch.add(resume);
patch.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
allowed.instructions.insert(patch);
var writer = new ClassWriter(reader, 0);
retained.accept(writer);
Files.write(Path.of(args[1]), writer.toByteArray());
}
private static void match(InsnList patch, String value, int local, LabelNode resume) {
patch.add(new LdcInsnNode(value));
patch.add(new VarInsnNode(Opcodes.ALOAD, local));
patch.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false));
patch.add(new JumpInsnNode(Opcodes.IFEQ, resume));
}
}

22
tools/plugin_ria_copy.py Normal file
View file

@ -0,0 +1,22 @@
"""Install the scoped ATM reference actions onto an exact retained menu archive."""
import argparse
from pathlib import Path
from plugin_wild_update import digest, read_archive, write_archive
ATM='com/dunerealms/menus/AtmMenu.class'
COPY='com/dunerealms/menus/RiaClipboard.class'
ATM_PREIMAGE='3139e7085a1779098e8651f4fc79b32ae67de58fe61a59155843c6e9bd93eb62'
def assemble(baseline,baseline_sha,donor,donor_sha,output):
old=baseline.read_bytes();payload=donor.read_bytes()
if digest(old)!=baseline_sha or digest(payload)!=donor_sha:raise ValueError('Unexpected archive checksum')
retained=read_archive(old);compiled=read_archive(payload)
if digest(retained[ATM])!=ATM_PREIMAGE:raise ValueError('Unexpected retained ATM implementation')
if COPY in retained or set(compiled)!={ATM,COPY}:raise ValueError('Unexpected ATM overlay scope')
retained.update(compiled)
with output.open('xb') as stream:stream.write(write_archive(retained))
if __name__=='__main__':
p=argparse.ArgumentParser(description=__doc__)
p.add_argument('baseline',type=Path);p.add_argument('baseline_sha');p.add_argument('donor',type=Path);p.add_argument('donor_sha');p.add_argument('output',type=Path)
assemble(**vars(p.parse_args()))

View file

@ -0,0 +1,52 @@
"""Build Sigma goat overlays from explicitly pinned live archives."""
import argparse
import json
from pathlib import Path
import subprocess
from tempfile import TemporaryDirectory
from plugin_wild_update import digest, read_archive, write_archive
CLASS = "com/example/duneterrain/PlanetMobs.class"
BIOMES = ("snowy_slopes", "frozen_peaks", "jagged_peaks")
def read_pinned(path, sha):
payload = path.read_bytes()
if digest(payload) != sha:
raise ValueError(f"Unexpected baseline: {path.name}")
return read_archive(payload)
def assemble(terrain, terrain_sha, biomes, biomes_sha, output, classpath):
existing = read_pinned(terrain, terrain_sha)
pack = read_pinned(biomes, biomes_sha)
for biome in BIOMES:
path = f"data/minecraft/worldgen/biome/{biome}.json"
data = json.loads(pack[path])
creatures = data["spawners"]["creature"]
if any(spawner["type"] == "minecraft:goat" for spawner in creatures):
raise ValueError(f"Goats already registered: {biome}")
creatures.append({"type": "minecraft:goat", "weight": 5, "minCount": 1, "maxCount": 3})
pack[path] = (json.dumps(data, ensure_ascii=False, indent=2) + "\n").encode()
with TemporaryDirectory() as temporary:
retained = Path(temporary) / "retained.class"
changed = Path(temporary) / "changed.class"
retained.write_bytes(existing[CLASS])
helper = Path(__file__).with_name("SigmaGoatMerge.java")
subprocess.run(["java", "--class-path", classpath, str(helper), str(retained), str(changed)], check=True)
existing[CLASS] = changed.read_bytes()
output.mkdir()
(output / terrain.name).write_bytes(write_archive(existing))
(output / biomes.name).write_bytes(write_archive(pack))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("terrain", type=Path)
parser.add_argument("terrain_sha")
parser.add_argument("biomes", type=Path)
parser.add_argument("biomes_sha")
parser.add_argument("output", type=Path)
parser.add_argument("classpath", help="ASM core and tree JARs")
assemble(**vars(parser.parse_args()))