Add the brewing stand to the menu engine and click harness
The brewing stand menu follows BrewingStandMenu: single-item potion slots, the ingredient and fuel slots with their quick move rules, checked against vanilla with potion bottles, ingredients and fuels in the random contents. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -79,9 +79,11 @@ fn main() -> horizon_client::Result<()> {
|
||||
let input = fs::read_to_string(args.get(2).ok_or("missing INPUT")?)?;
|
||||
let items = Items::catalog(root)?;
|
||||
let recipes = Recipes::load(root, &items)?;
|
||||
let brewing = horizon_client::brewing::Brewing::load(root, &items);
|
||||
let env = Env {
|
||||
items: &items,
|
||||
recipes: &recipes,
|
||||
brewing: &brewing,
|
||||
};
|
||||
let mut out = String::new();
|
||||
for line in input.lines() {
|
||||
|
||||
@@ -34,9 +34,11 @@ fn main() -> horizon_client::Result<()> {
|
||||
let input = fs::read_to_string(args.get(2).ok_or("missing INPUT")?)?;
|
||||
let items = Items::catalog(root)?;
|
||||
let recipes = Recipes::load(root, &items)?;
|
||||
let brewing = horizon_client::brewing::Brewing::load(root, &items);
|
||||
let env = Env {
|
||||
items: &items,
|
||||
recipes: &recipes,
|
||||
brewing: &brewing,
|
||||
};
|
||||
let mut out = String::new();
|
||||
for line in input.lines() {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
//! `tools/test_menu_click_parity.py` compares every click with vanilla's menu
|
||||
//! classes.
|
||||
use crate::{
|
||||
brewing::Brewing,
|
||||
crafting::Recipes,
|
||||
items::{ItemStack, Items},
|
||||
};
|
||||
@@ -13,6 +14,7 @@ use crate::{
|
||||
pub struct Env<'a> {
|
||||
pub items: &'a Items,
|
||||
pub recipes: &'a Recipes,
|
||||
pub brewing: &'a Brewing,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
@@ -51,6 +53,7 @@ pub enum Kind {
|
||||
Shulker,
|
||||
/// The cooking recipe type: smelting, blasting or smoking.
|
||||
Furnace(&'static str),
|
||||
Brewing,
|
||||
}
|
||||
|
||||
impl Kind {
|
||||
@@ -67,6 +70,7 @@ impl Kind {
|
||||
"furnace" => Self::Furnace("smelting"),
|
||||
"blast_furnace" => Self::Furnace("blasting"),
|
||||
"smoker" => Self::Furnace("smoking"),
|
||||
"brewing" => Self::Brewing,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -84,6 +88,12 @@ enum Role {
|
||||
Output,
|
||||
/// `ResultSlot` of a crafting grid.
|
||||
CraftResult,
|
||||
/// `BrewingStandMenu.PotionSlot`.
|
||||
Potion,
|
||||
/// `BrewingStandMenu.IngredientsSlot`.
|
||||
Ingredient,
|
||||
/// `BrewingStandMenu.FuelSlot`.
|
||||
BrewFuel,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -220,6 +230,27 @@ impl Menu {
|
||||
slots.extend(main(27, Role::Shulker));
|
||||
player(&mut slots);
|
||||
}
|
||||
Kind::Brewing => {
|
||||
containers[MAIN] = vec![None; 5];
|
||||
for (index, role) in [
|
||||
Role::Potion,
|
||||
Role::Potion,
|
||||
Role::Potion,
|
||||
Role::Ingredient,
|
||||
Role::BrewFuel,
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
slots.push(Slot {
|
||||
container: MAIN,
|
||||
index,
|
||||
role,
|
||||
});
|
||||
}
|
||||
player(&mut slots);
|
||||
data = 4;
|
||||
}
|
||||
Kind::Furnace(_) => {
|
||||
containers[MAIN] = vec![None; 3];
|
||||
slots.extend([
|
||||
@@ -349,6 +380,19 @@ impl Menu {
|
||||
Role::Shulker => Self::fits_inside(stack),
|
||||
Role::Fuel => Self::is_fuel(env, stack) || Self::is_bucket(stack),
|
||||
Role::Output | Role::CraftResult => false,
|
||||
Role::Potion => {
|
||||
env.brewing.is_bottle(stack)
|
||||
|| env
|
||||
.items
|
||||
.item_tags
|
||||
.get("minecraft:brewing_potion_inputs")
|
||||
.is_some_and(|m| m.contains(&*stack.item))
|
||||
}
|
||||
Role::Ingredient => env.brewing.is_reagent(stack),
|
||||
Role::BrewFuel => env
|
||||
.items
|
||||
.get(&stack.item)
|
||||
.is_some_and(|i| i.brewing_fuel.is_some()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +411,7 @@ impl Menu {
|
||||
/// `Slot.getMaxStackSize(stack)`.
|
||||
fn slot_max(&self, env: &Env, s: usize, stack: &ItemStack) -> u32 {
|
||||
let own = match self.slots[s].role {
|
||||
Role::Armor(_) => 1,
|
||||
Role::Armor(_) | Role::Potion => 1,
|
||||
Role::Fuel if Self::is_bucket(stack) => return 1,
|
||||
_ => CONTAINER_MAX,
|
||||
};
|
||||
@@ -742,6 +786,56 @@ impl Menu {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Kind::Brewing => {
|
||||
after_take = true;
|
||||
let slot = self.slots[index];
|
||||
let commit = |m: &mut Self, stack: &ItemStack| {
|
||||
m.containers[slot.container][slot.index] =
|
||||
(stack.count > 0).then(|| stack.clone());
|
||||
};
|
||||
if index <= 4 {
|
||||
if !self.move_to(env, &mut stack, 5, 41, true) {
|
||||
return None;
|
||||
}
|
||||
} else if env
|
||||
.items
|
||||
.get(&clicked.item)
|
||||
.is_some_and(|i| i.brewing_fuel.is_some())
|
||||
{
|
||||
let moved = self.move_to(env, &mut stack, 4, 5, false);
|
||||
if moved
|
||||
|| (env.brewing.is_reagent(&stack)
|
||||
&& !self.move_to(env, &mut stack, 3, 4, false))
|
||||
{
|
||||
commit(self, &stack);
|
||||
return None;
|
||||
}
|
||||
} else if env.brewing.is_reagent(&stack) {
|
||||
if !self.move_to(env, &mut stack, 3, 4, false) {
|
||||
return None;
|
||||
}
|
||||
} else if env.brewing.is_bottle(&stack)
|
||||
|| env
|
||||
.items
|
||||
.item_tags
|
||||
.get("minecraft:brewing_potion_inputs")
|
||||
.is_some_and(|m| m.contains(&*stack.item))
|
||||
{
|
||||
if !self.move_to(env, &mut stack, 0, 3, false) {
|
||||
return None;
|
||||
}
|
||||
} else if (5..32).contains(&index) {
|
||||
if !self.move_to(env, &mut stack, 32, 41, false) {
|
||||
return None;
|
||||
}
|
||||
} else if (32..41).contains(&index) {
|
||||
if !self.move_to(env, &mut stack, 5, 32, false) {
|
||||
return None;
|
||||
}
|
||||
} else if !self.move_to(env, &mut stack, 5, 41, false) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Kind::Furnace(recipe) => {
|
||||
after_take = true;
|
||||
if index == 2 {
|
||||
|
||||
@@ -19,22 +19,25 @@ except ImportError:
|
||||
import lab
|
||||
|
||||
MENUS = {'inventory': 46, 'crafting': 46, 'chest1': 45, 'chest2': 54, 'chest3': 63, 'chest4': 72, 'chest5': 81,
|
||||
'chest6': 90, 'hopper': 41, 'dispenser': 45, 'shulker': 63, 'furnace': 39, 'blast_furnace': 39, 'smoker': 39}
|
||||
DATA = {'furnace': 4, 'blast_furnace': 4, 'smoker': 4}
|
||||
'chest6': 90, 'hopper': 41, 'dispenser': 45, 'shulker': 63, 'furnace': 39, 'blast_furnace': 39, 'smoker': 39, 'brewing': 41}
|
||||
DATA = {'furnace': 4, 'blast_furnace': 4, 'smoker': 4, 'brewing': 4}
|
||||
COMMON = ['stone', 'dirt', 'cobblestone', 'oak_planks', 'stick', 'coal', 'iron_ingot', 'diamond', 'apple', 'bread',
|
||||
'oak_log', 'sand', 'bucket', 'water_bucket', 'lava_bucket', 'ender_pearl', 'snowball', 'egg', 'white_wool',
|
||||
'iron_helmet', 'diamond_chestplate', 'leather_leggings', 'iron_boots', 'shield', 'carved_pumpkin',
|
||||
'elytra', 'turtle_helmet', 'iron_sword', 'diamond_pickaxe', 'bow', 'shulker_box', 'red_shulker_box',
|
||||
'raw_iron', 'potato', 'beef', 'chicken', 'sticky_piston', 'blaze_rod', 'lava_bucket', 'oak_sapling',
|
||||
'white_dye', 'red_dye', 'torch', 'crafting_table', 'furnace', 'chest']
|
||||
'white_dye', 'red_dye', 'torch', 'crafting_table', 'furnace', 'chest', 'glass_bottle', 'nether_wart', 'blaze_powder',
|
||||
'redstone', 'gunpowder', 'sugar', 'potion', 'splash_potion', 'lingering_potion', 'fermented_spider_eye', 'dragon_breath']
|
||||
|
||||
|
||||
def quote(text):
|
||||
return '"' + text + '"'
|
||||
|
||||
|
||||
def snbt(item, count, damage=0, curse=False):
|
||||
def snbt(item, count, damage=0, curse=False, potion=None):
|
||||
comps = []
|
||||
if potion:
|
||||
comps.append('"minecraft:potion_contents":{potion:"%s"}' % potion)
|
||||
if damage:
|
||||
comps.append('"minecraft:damage":%d' % damage)
|
||||
if curse:
|
||||
@@ -60,7 +63,8 @@ class Gen:
|
||||
if info.get('minecraft:max_damage') and rng.random() < 0.3:
|
||||
damage = rng.randrange(1, info['minecraft:max_damage'])
|
||||
count = 1 if top == 1 else rng.choice([1, 1, 2, top, top, top - 1, rng.randrange(1, top + 1)])
|
||||
return snbt(item, max(1, count), damage, curse=rng.random() < 0.15 and 'equippable' in json.dumps(info))
|
||||
potion = rng.choice(['minecraft:water', 'minecraft:awkward', 'minecraft:healing', 'minecraft:thick']) if item.endswith('potion') and rng.random() < 0.8 else None
|
||||
return snbt(item, max(1, count), damage, curse=rng.random() < 0.15 and 'equippable' in json.dumps(info), potion=potion)
|
||||
|
||||
def slots(self, size, density):
|
||||
return [self.stack() if self.rng.random() < density else '-' for _ in range(size)]
|
||||
|
||||
Reference in New Issue
Block a user