Keep origin metadata on stonecutter and crafter output
This commit is contained in:
parent
fe589553aa
commit
bf08c6b1c2
3 changed files with 116 additions and 4 deletions
41
.forgejo/workflows/workstation-origin.yml
Normal file
41
.forgejo/workflows/workstation-origin.yml
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
name: Workstation Origin Overlay
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/workstation-origin-*']
|
||||
|
||||
jobs:
|
||||
workstation-origin:
|
||||
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 and build the single-class overlay
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p JarvisConnector test jar
|
||||
mkdir workstation-origin
|
||||
python3 tools/plugin_workstation_origin.py extract JarvisConnector/build/libs/jarvistranslator.jar workstation-origin/workstation-origin.overlay.zip
|
||||
cp tools/{plugin_workstation_origin,plugin_wild_update}.py workstation-origin/
|
||||
printf '%s\n' "$GITHUB_SHA" > workstation-origin/SOURCE_COMMIT
|
||||
(cd workstation-origin && sha256sum -- *.zip *.py SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Workstation-Origin
|
||||
path: workstation-origin
|
||||
if-no-files-found: error
|
||||
|
|
@ -9,6 +9,7 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|||
import org.bukkit.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.*;
|
||||
import org.bukkit.event.block.CrafterCraftEvent;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.player.*;
|
||||
|
|
@ -27,6 +28,7 @@ final class ItemMetadataOverlay implements Listener {
|
|||
private final Map<Material,ItemMetadataPolicy.Grade> nativeGrades=new EnumMap<>(Material.class);
|
||||
private final Map<Material,ItemMetadataPolicy.Grade> craftingGrades=new EnumMap<>(Material.class);
|
||||
private final Set<UUID> pending=new HashSet<>();
|
||||
private boolean crafterRegistered;
|
||||
ItemMetadataOverlay(Plugin plugin)throws IOException {
|
||||
this.plugin=plugin;planetItemArtwork=plugin.getConfig().getBoolean("central-pack.item-artwork",false);policy=new ItemMetadataPolicy(plugin.getResource("item-templates.json"));
|
||||
Bukkit.getPluginManager().registerEvents(this,plugin);
|
||||
|
|
@ -191,7 +193,16 @@ final class ItemMetadataOverlay implements Listener {
|
|||
var resolved=CraftingGrades.resolve(baseline,fixed,recipes);craftingGrades.clear();
|
||||
resolved.forEach((name,mark)->{if(!fixed.containsKey(name))craftingGrades.put(Material.valueOf(name),new ItemMetadataPolicy.Grade(CraftingGrades.quality(mark),String.valueOf(mark),"resource"));});
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void serverLoaded(org.bukkit.event.server.ServerLoadEvent e){craftingRecipes();cookingRecipes();for(Player p:Bukkit.getOnlinePlayers())later(p);}
|
||||
@EventHandler(priority=EventPriority.MONITOR)
|
||||
public void serverLoaded(org.bukkit.event.server.ServerLoadEvent event){
|
||||
if(!crafterRegistered){
|
||||
// Recipe-specific listeners may replace the result. Register after plugin enable.
|
||||
Bukkit.getPluginManager().registerEvent(CrafterCraftEvent.class,this,EventPriority.HIGHEST,
|
||||
(listener,craft)->automatedCraft((CrafterCraftEvent)craft),plugin,true);
|
||||
crafterRegistered=true;
|
||||
}
|
||||
craftingRecipes();cookingRecipes();for(Player p:Bukkit.getOnlinePlayers())later(p);
|
||||
}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void join(PlayerJoinEvent e){later(e.getPlayer());}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void open(InventoryOpenEvent e){if(e.getPlayer() instanceof Player p)later(p);}
|
||||
@EventHandler(priority=EventPriority.MONITOR) public void close(InventoryCloseEvent e){if(e.getPlayer() instanceof Player p)later(p);}
|
||||
|
|
@ -206,9 +217,28 @@ final class ItemMetadataOverlay implements Listener {
|
|||
@EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) public void moved(InventoryMoveItemEvent e){Bukkit.getScheduler().runTask(plugin,()->{inventory(e.getSource());inventory(e.getDestination());});}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void smelt(FurnaceSmeltEvent e){var result=e.getResult().clone();ItemOrigin.created(result);stamp(result);e.setResult(result);}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void craft(PrepareItemCraftEvent e){var result=e.getInventory().getResult();if(result!=null){result=result.clone();ItemOrigin.created(result);stamp(result);e.getInventory().setResult(result);}}
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true) public void stonecut(io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent e){
|
||||
var source=e.getStonecuttingRecipe();var result=source.getResult().clone();ItemOrigin.created(result);stamp(result);
|
||||
var recipe=new StonecuttingRecipe(source.getKey(),result,source.getInputChoice());recipe.setGroup(source.getGroup());e.setStonecuttingRecipe(recipe);
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
|
||||
public void stonecut(InventoryClickEvent event){
|
||||
if(!(event.getView().getTopInventory() instanceof StonecutterInventory stonecutter)
|
||||
||event.getClickedInventory()!=stonecutter||event.getSlotType()!=InventoryType.SlotType.RESULT
|
||||
||event.getAction()==InventoryAction.NOTHING)return;
|
||||
var location=stonecutter.getLocation();
|
||||
var world=location==null?event.getWhoClicked().getWorld():location.getWorld();
|
||||
var result=createdOutput(event.getCurrentItem(),world);
|
||||
if(result!=null)event.setCurrentItem(result);
|
||||
}
|
||||
|
||||
private void automatedCraft(CrafterCraftEvent event){
|
||||
var result=createdOutput(event.getResult(),event.getBlock().getWorld());
|
||||
if(result!=null)event.setResult(result);
|
||||
}
|
||||
|
||||
private ItemStack createdOutput(ItemStack original,World world){
|
||||
if(original==null||original.isEmpty()||world==null)return null;
|
||||
var result=original.clone();
|
||||
ItemOrigin.created(result,world.getName());
|
||||
stamp(result);
|
||||
return result;
|
||||
}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void died(EntityDeathEvent e){
|
||||
var equipment=e.getEntity().getEquipment();var carried=new ArrayList<ItemStack>();
|
||||
|
|
|
|||
41
tools/plugin_workstation_origin.py
Normal file
41
tools/plugin_workstation_origin.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
"""Build and apply the scoped workstation provenance class overlay."""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from plugin_wild_update import digest, read_archive, write_archive
|
||||
|
||||
ENTRY = "com/dunerealms/jarvis/ItemMetadataOverlay.class"
|
||||
|
||||
|
||||
def extract(built, output):
|
||||
compiled = read_archive(built.read_bytes())
|
||||
output.write_bytes(write_archive({ENTRY: compiled[ENTRY]}))
|
||||
|
||||
|
||||
def assemble(baseline, baseline_sha, patch, patch_sha, output):
|
||||
baseline_bytes = baseline.read_bytes()
|
||||
patch_bytes = patch.read_bytes()
|
||||
if digest(baseline_bytes) != baseline_sha or digest(patch_bytes) != patch_sha:
|
||||
raise ValueError("Unexpected baseline or overlay checksum")
|
||||
retained = read_archive(baseline_bytes)
|
||||
overlay = read_archive(patch_bytes)
|
||||
if set(overlay) != {ENTRY} or ENTRY not in retained or retained[ENTRY] == overlay[ENTRY]:
|
||||
raise ValueError("Expected one replacement class in an existing JarvisConnector JAR")
|
||||
output.write_bytes(write_archive(retained | overlay))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
sub = parser.add_subparsers(dest="action", required=True)
|
||||
pack = sub.add_parser("extract")
|
||||
pack.add_argument("built", type=Path)
|
||||
pack.add_argument("output", type=Path)
|
||||
merge = sub.add_parser("assemble")
|
||||
merge.add_argument("baseline", type=Path)
|
||||
merge.add_argument("baseline_sha")
|
||||
merge.add_argument("patch", type=Path)
|
||||
merge.add_argument("patch_sha")
|
||||
merge.add_argument("output", type=Path)
|
||||
args = vars(parser.parse_args())
|
||||
(extract if args.pop("action") == "extract" else assemble)(**args)
|
||||
Loading…
Reference in a new issue

Staff