Grindstone on the menu engine; LAN guests use grindstones
GrindstoneMenu now runs on horizon_client::menu (Kind::Grindstone): its input filter, computeResult, the result's onTake (both inputs cleared, the experience sum handed to the caller) and quickMoveStack, verified against the vanilla class by test_menu_click_parity with enchanted, damaged and cursed tools and books. Single player routes the grindstone's clicks, drags and double clicks through the engine and rolls the orbs and level event 1042 (now playing block.grindstone.use) where the result is taken. The LAN host opens minecraft:grindstone for guests on the same engine and awards the orbs at the block; guests read enchantments, stored enchantments, repair cost and custom names from the server's stacks, and the host now sends repair cost. Part of #868. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+50
-1
@@ -42,6 +42,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
- stonecutter: a stonecutter opens on the guest's screen with the recipes of the stone the guest puts
|
||||
in; the guest picks the slab and shift-clicks the result, and the server has cut every
|
||||
stone into slabs (#868);
|
||||
- grindstone: a grindstone opens on the guest's screen; the enchanted sword the guest shift-clicks in
|
||||
shows the server's result, and the guest takes it with only its curse left and the
|
||||
experience orbs the server awards (#868);
|
||||
- feedback: the guest's command feedback names the guest and shows the numbers;
|
||||
- chat: a line the host sends reaches the guest's event log (`wait-for chat`), and on the
|
||||
server thread the host window's too;
|
||||
@@ -136,7 +139,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
GUEST_NAME = 'Guest'
|
||||
# The host plays single player on its server thread (--server-thread).
|
||||
SERVER_THREAD = False
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -993,6 +996,51 @@ def check_stonecutter(host, guest, out):
|
||||
return seen
|
||||
|
||||
|
||||
def server_reply(guest, command, *needles):
|
||||
"""The first chat line holding every needle after the guest runs `command`."""
|
||||
since = guest.raw('events')['last']
|
||||
guest('command', command=command)
|
||||
for _ in range(0, 65):
|
||||
reply = guest.raw('events', '--since', since)
|
||||
for e in reply['events']:
|
||||
line = e.get('text', '')
|
||||
if e.get('event') == 'chat' and all(n in line for n in needles):
|
||||
return line
|
||||
guest.wait(2)
|
||||
raise Failed(f'no answer to {command}')
|
||||
|
||||
|
||||
def check_grindstone(host, guest, out):
|
||||
guest('command', command='gamemode survival')
|
||||
guest('command', command='clear @s')
|
||||
guest('command', command='xp set @s 0 levels')
|
||||
guest('command', command='xp set @s 0 points')
|
||||
guest('command', command='give @s minecraft:iron_sword[minecraft:enchantments={"minecraft:sharpness":3,'
|
||||
'"minecraft:vanishing_curse":1},minecraft:damage=100]')
|
||||
at = open_station(guest, 'grindstone', out, 'grindstone')
|
||||
# GrindstoneMenu.quickMoveStack: with both inputs empty, into the first.
|
||||
guest.raw('click-slot', hotbar_slot(guest, 'minecraft:iron_sword'), 'shift')
|
||||
guest.wait(10)
|
||||
loaded = station_slots(guest)
|
||||
guest.shot(out, 'grindstone-result')
|
||||
guest.raw('click-slot', 650, 'shift')
|
||||
# The orbs (sharpness III: 12 to 23 points) fly to the guest.
|
||||
guest.wait(60)
|
||||
left = station_slots(guest)
|
||||
close_station(guest, at)
|
||||
sword = server_reply(guest, 'data get entity @s Inventory[{id:"minecraft:iron_sword"}].components',
|
||||
'minecraft:damage')
|
||||
xp = server_reply(guest, 'xp query @s points', 'experience points')
|
||||
seen = {'loaded': loaded, 'left': left, 'curse kept': 'vanishing_curse' in sword,
|
||||
'sharpness gone': 'sharpness' not in sword,
|
||||
'damage': re.search(r'minecraft:damage"?: 100\b', sword) is not None,
|
||||
'xp': int(re.search(r'has (\d+) experience', xp).group(1)) > 0}
|
||||
want = {'loaded': {600: ('minecraft:iron_sword', 1), 650: ('minecraft:iron_sword', 1)}, 'left': {},
|
||||
'curse kept': True, 'sharpness gone': True, 'damage': True, 'xp': True}
|
||||
assert seen == want, f'the grindstone on the guest: {seen} ({sword!r}, {xp!r})'
|
||||
return seen
|
||||
|
||||
|
||||
def slot_point(game, slot):
|
||||
"""The GUI point in the middle of slot `slot` of the open screen (`ui`'s slot-N)."""
|
||||
for w in game.raw('ui')['widgets']:
|
||||
@@ -2186,6 +2234,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'brewing': check_brewing,
|
||||
'loom': check_loom,
|
||||
'stonecutter': check_stonecutter,
|
||||
'grindstone': check_grindstone,
|
||||
'hurt': check_hurt,
|
||||
'commands': check_commands,
|
||||
'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls,
|
||||
|
||||
@@ -11,7 +11,8 @@ item the first click moved) over the player inventory,
|
||||
crafting table, chests, hopper, dispenser, shulker box, the furnaces, the
|
||||
brewing stand, the crafter (the client's menu, and the server's over the block
|
||||
entity with slot state packets), the loom (with its pattern buttons), the
|
||||
stonecutter (with its recipe buttons) and the
|
||||
stonecutter (with its recipe buttons), the grindstone (enchanted, damaged and
|
||||
cursed tools and books) and the
|
||||
server's furnace menus over their block entities (`*_be`: a new input restarts
|
||||
cooking, other clicks keep its progress). After
|
||||
every click the slots, carried stack, data slots and drops are compared.
|
||||
@@ -27,7 +28,7 @@ except ImportError:
|
||||
|
||||
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, 'brewing': 41, 'crafter': 46,
|
||||
'crafter_be': 46, 'loom': 40, 'stonecutter': 38, 'furnace_be': 39, 'blast_furnace_be': 39, 'smoker_be': 39}
|
||||
'crafter_be': 46, 'loom': 40, 'stonecutter': 38, 'grindstone': 39, 'furnace_be': 39, 'blast_furnace_be': 39, 'smoker_be': 39}
|
||||
DATA = {'furnace': 4, 'blast_furnace': 4, 'smoker': 4, 'brewing': 4, 'crafter': 10, 'crafter_be': 10, 'loom': 1,
|
||||
'stonecutter': 1,
|
||||
'furnace_be': 4, 'blast_furnace_be': 4, 'smoker_be': 4}
|
||||
@@ -45,6 +46,10 @@ COMMON = ['stone', 'dirt', 'cobblestone', 'oak_planks', 'stick', 'coal', 'iron_i
|
||||
# Stonecutter inputs (several recipes each), and a block it doesn't cut.
|
||||
CUTTABLE = ['stone', 'cobblestone', 'andesite', 'granite', 'copper_block', 'sandstone', 'quartz_block', 'deepslate',
|
||||
'stone_bricks', 'oak_planks']
|
||||
# Grindstone inputs: tools and armor, books, and their enchantments (curses too).
|
||||
GRINDABLE = ['iron_sword', 'diamond_pickaxe', 'bow', 'iron_helmet', 'elytra', 'shield', 'fishing_rod', 'trident']
|
||||
ENCHANTS = ['sharpness', 'unbreaking', 'mending', 'efficiency', 'protection', 'power', 'looting', 'fortune',
|
||||
'binding_curse', 'vanishing_curse']
|
||||
|
||||
|
||||
def quote(text):
|
||||
@@ -109,6 +114,33 @@ class Gen:
|
||||
return snbt('minecraft:' + rng.choice(CUTTABLE), rng.choice([1, 1, 2, 3, 10, 63, 64]))
|
||||
return self.stack()
|
||||
|
||||
def grind_stack(self):
|
||||
"""Mostly an enchanted or damaged tool or an enchanted book, sometimes anything."""
|
||||
rng = self.rng
|
||||
roll = rng.random()
|
||||
if roll > 0.8:
|
||||
return self.stack()
|
||||
levels = ','.join('"minecraft:%s":%d' % (e, rng.randrange(1, 4))
|
||||
for e in rng.sample(ENCHANTS, rng.choice([0, 1, 1, 2, 3])))
|
||||
comps = []
|
||||
if roll < 0.25:
|
||||
item = 'minecraft:' + rng.choice(['enchanted_book', 'enchanted_book', 'book'])
|
||||
if levels:
|
||||
comps.append('"minecraft:stored_enchantments":{%s}' % levels)
|
||||
count = 1 if rng.random() < 0.85 else 2
|
||||
else:
|
||||
item = 'minecraft:' + rng.choice(GRINDABLE)
|
||||
info = self.items.get(item, {})
|
||||
if levels:
|
||||
comps.append('"minecraft:enchantments":{%s}' % levels)
|
||||
if info.get('minecraft:max_damage') and rng.random() < 0.6:
|
||||
comps.append('"minecraft:damage":%d' % rng.randrange(0, info['minecraft:max_damage']))
|
||||
count = 1
|
||||
if rng.random() < 0.2:
|
||||
comps.append('"minecraft:repair_cost":%d' % rng.choice([1, 3, 7]))
|
||||
body = ',components:{%s}' % ','.join(comps) if comps else ''
|
||||
return '{id:%s,count:%d%s}' % (quote(item), count, body)
|
||||
|
||||
def recipe(self, slots, width, start=1):
|
||||
"""Fills the crafting grid (slots `start`..) with a small known recipe."""
|
||||
rng = self.rng
|
||||
@@ -142,6 +174,9 @@ class Gen:
|
||||
if menu == 'stonecutter' and rng.random() < 0.2:
|
||||
out.append([1, rng.randrange(0, 2), rng.choice(['PICKUP', 'QUICK_MOVE', 'QUICK_MOVE', 'THROW', 'SWAP'])])
|
||||
continue
|
||||
if menu == 'grindstone' and rng.random() < 0.2:
|
||||
out.append([2, rng.randrange(0, 2), rng.choice(['PICKUP', 'QUICK_MOVE', 'QUICK_MOVE', 'THROW', 'SWAP'])])
|
||||
continue
|
||||
if menu == 'crafter_be' and rng.random() < 0.2:
|
||||
out.append([rng.choice([0, 1, 4, 8, 8, 9, -1]), rng.randrange(0, 2), 'SLOT_STATE'])
|
||||
continue
|
||||
@@ -208,6 +243,16 @@ def main():
|
||||
slots[0] = g.cut_stack() if rng.random() < 0.8 else '-'
|
||||
# The result follows the input and the selected recipe; a fixture stack there is rare.
|
||||
slots[1] = '-' if rng.random() < 0.9 else g.cut_stack()
|
||||
if menu == 'grindstone':
|
||||
for i in rng.sample(range(3, size), 10):
|
||||
slots[i] = g.grind_stack()
|
||||
slots[0] = g.grind_stack() if rng.random() < 0.7 else '-'
|
||||
slots[1] = g.grind_stack() if rng.random() < 0.6 else '-'
|
||||
# Two of the same tool, so mergeItems runs.
|
||||
if slots[0] != '-' and rng.random() < 0.3:
|
||||
slots[1] = slots[0] if rng.random() < 0.4 else g.grind_stack()
|
||||
# The result follows the inputs; a fixture stack there is rare.
|
||||
slots[2] = '-' if rng.random() < 0.9 else g.grind_stack()
|
||||
if menu == 'crafter_be':
|
||||
slots[45] = '-'
|
||||
if rng.random() < 0.6:
|
||||
@@ -236,7 +281,7 @@ def main():
|
||||
if menu in ('loom', 'stonecutter'):
|
||||
return rng.choice([-1, -1, 0, 0, 1, 2, 3, 30])
|
||||
return 0
|
||||
carried = {'loom': g.loom_stack, 'stonecutter': g.cut_stack}.get(menu, g.stack)() if rng.random() < 0.5 else '-'
|
||||
carried = {'loom': g.loom_stack, 'stonecutter': g.cut_stack, 'grindstone': g.grind_stack}.get(menu, g.stack)() if rng.random() < 0.5 else '-'
|
||||
if carried_food is not None:
|
||||
carried = carried_food
|
||||
cases.append({'menu': menu, 'creative': rng.random() < 0.25, 'slots': slots,
|
||||
|
||||
Reference in New Issue
Block a user