Keep Arrakis-only food registration out of Lobby startup
This commit is contained in:
parent
670ad0de5f
commit
ac64d0d5f2
4 changed files with 101 additions and 0 deletions
41
.forgejo/workflows/lobby-food-startup.yml
Normal file
41
.forgejo/workflows/lobby-food-startup.yml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
name: Lobby Food Startup Build
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/lobby-food-startup-*']
|
||||
|
||||
jobs:
|
||||
lobby-food:
|
||||
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 Lobby listener patch
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p JarvisConnector test jar
|
||||
mkdir lobby-food-artifacts
|
||||
python3 tools/plugin_lobby_food.py JarvisConnector/build/libs/jarvistranslator.jar lobby-food-artifacts/lobby-food-classes.zip
|
||||
cp tools/plugin_lobby_food.py lobby-food-artifacts/
|
||||
printf '%s\n' "$(git rev-parse HEAD)" > lobby-food-artifacts/SOURCE_COMMIT
|
||||
(cd lobby-food-artifacts && sha256sum -- lobby-food-classes.zip plugin_lobby_food.py SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Lobby-Food-Startup
|
||||
path: lobby-food-artifacts/
|
||||
if-no-files-found: error
|
||||
|
|
@ -37,6 +37,7 @@ final class ArrakisBrewing implements Listener {
|
|||
meta.getPersistentDataContainer().set(BOOSTED,PersistentDataType.BYTE,(byte)1);item.setItemMeta(meta);return item;
|
||||
}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void loaded(ServerLoadEvent event){
|
||||
if(SurvivalFoodRecipes.lobbyProfile(plugin))return;
|
||||
try{water=recipes.nativeItem("jerboa_water_vial");life=recipes.nativeItem("water_of_life");metadata.stamp(water);metadata.stamp(life);
|
||||
var brewer=Bukkit.getPotionBrewer();brewer.removePotionMix(MIX);
|
||||
brewer.addPotionMix(new PotionMix(MIX,water,PotionMix.createPredicateChoice(item->vial(item,"blood_vial")),PotionMix.createPredicateChoice(ArrakisBrewing::spice)));
|
||||
|
|
|
|||
|
|
@ -18,12 +18,18 @@ final class SurvivalFoodRecipes implements Listener {
|
|||
private final ItemMetadataOverlay metadata;
|
||||
private static final NamespacedKey VIALS=new NamespacedKey("dunerealms","imported_water_vials");
|
||||
SurvivalFoodRecipes(Plugin plugin,ItemMetadataOverlay metadata){this.plugin=plugin;this.metadata=metadata;Bukkit.getPluginManager().registerEvents(this,plugin);}
|
||||
static boolean lobbyProfile(Plugin plugin){
|
||||
return "lobby".equalsIgnoreCase(plugin.getConfig().getString("native.server-key",
|
||||
plugin.getDataFolder().getAbsoluteFile().getParentFile().getParentFile().getName()));
|
||||
}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void loaded(ServerLoadEvent event){
|
||||
try(var stream=plugin.getResource("survival-food-recipes.json")){
|
||||
if(stream==null)throw new IOException("Missing smoker projection policy");
|
||||
var policy=JsonParser.parseReader(new InputStreamReader(stream,StandardCharsets.UTF_8)).getAsJsonObject();if(policy.get("version").getAsInt()!=1)throw new IOException("Unsupported food policy");
|
||||
boolean lobby=lobbyProfile(plugin);
|
||||
for(var element:policy.getAsJsonArray("smoker")){
|
||||
var spec=element.getAsJsonObject();String id=spec.get("id").getAsString();var key=new NamespacedKey("dunerealms",id);int amount=spec.get("amount").getAsInt();if(amount<1||amount>64)throw new IOException("Invalid smoker quantity");
|
||||
if(lobby&&id.equals("chukka_cooked_meat")){Bukkit.removeRecipe(key);continue;}
|
||||
ItemStack result=nativeItem(spec.get("result").getAsString());result.setAmount(amount);metadata.stamp(result);
|
||||
var variants=new ArrayList<ItemStack>();
|
||||
for(ItemStack input:List.of(nativeItem(spec.get("input").getAsString()),Bukkit.getItemFactory().createItemStack(spec.get("inputCommand").getAsString()))){
|
||||
|
|
@ -33,6 +39,7 @@ final class SurvivalFoodRecipes implements Listener {
|
|||
Bukkit.removeRecipe(key);if(!Bukkit.addRecipe(new SmokingRecipe(key,result,new RecipeChoice.ExactChoice(variants),.35f,100)))throw new IOException("Native smoker recipe rejected: "+id);
|
||||
}
|
||||
plugin.getLogger().info("Survival food smoker recipes registered; native fuel, hoppers and shift extraction retained.");
|
||||
if(lobby){Bukkit.removeRecipe(VIALS);return;}
|
||||
var vials=nativeItem("jerboa_water_vial");metadata.stamp(vials);vials.setAmount(6);
|
||||
Bukkit.removeRecipe(VIALS);var imported=new ShapelessRecipe(VIALS,vials);imported.addIngredient(Material.WATER_BUCKET);if(!Bukkit.addRecipe(imported))throw new IOException("Imported water recipe rejected");
|
||||
}catch(IOException|ReflectiveOperationException|RuntimeException failure){throw new IllegalStateException("Survival food recipe projection unavailable",failure);}
|
||||
|
|
|
|||
52
tools/plugin_lobby_food.py
Normal file
52
tools/plugin_lobby_food.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import argparse
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
|
||||
BASELINE = '5c632e3db85fc58e55c1917b29916ef1865b3c9eca3e3e70b9131ef44dad1aaf'
|
||||
CLASSES = tuple(f'com/dunerealms/jarvis/{name}.class'
|
||||
for name in ('ArrakisBrewing', 'SurvivalFoodRecipes'))
|
||||
|
||||
|
||||
def unique_names(archive):
|
||||
names = archive.namelist()
|
||||
if len(names) != len(set(names)):
|
||||
raise ValueError('Duplicate archive entry')
|
||||
return set(names)
|
||||
|
||||
|
||||
def extract(compiled, output):
|
||||
with ZipFile(compiled) as jar, ZipFile(output, 'x', ZIP_DEFLATED) as patch:
|
||||
unique_names(jar)
|
||||
for name in CLASSES:
|
||||
patch.writestr(name, jar.read(name))
|
||||
|
||||
|
||||
def assemble(baseline, patch, output):
|
||||
if hashlib.sha256(baseline.read_bytes()).hexdigest() != BASELINE:
|
||||
raise ValueError('Expected the exact retained Lobby JARVIS baseline')
|
||||
with ZipFile(baseline) as original, ZipFile(patch) as updates:
|
||||
names = unique_names(original)
|
||||
if unique_names(updates) != set(CLASSES) or not set(CLASSES) <= names:
|
||||
raise ValueError('Expected only the two reviewed Lobby recipe listeners')
|
||||
replacements = {name: updates.read(name) for name in CLASSES}
|
||||
if any(not data.startswith(b'\xca\xfe\xba\xbe') or data == original.read(name)
|
||||
for name, data in replacements.items()):
|
||||
raise ValueError('Invalid or unchanged Lobby listener class')
|
||||
with ZipFile(output, 'x', ZIP_DEFLATED) as candidate:
|
||||
for entry in original.infolist():
|
||||
data = replacements[entry.filename] if entry.filename in replacements else original.read(entry)
|
||||
candidate.writestr(entry, data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('input', type=Path)
|
||||
parser.add_argument('output', type=Path)
|
||||
parser.add_argument('--baseline', type=Path)
|
||||
args = parser.parse_args()
|
||||
if args.baseline is None:
|
||||
extract(args.input, args.output)
|
||||
else:
|
||||
assemble(args.baseline, args.input, args.output)
|
||||
Loading…
Reference in a new issue

Staff