Merge branch 'fix/st2-entity-hands' into fix/st2-chat
# Conflicts: # tools/lan_e2e.py
This commit is contained in:
+483
-27
@@ -146,6 +146,28 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
get off by sneaking; the other side sees the animal move.
|
||||
- lightning: a bolt summoned beside the host, then the guest: both sides get the bolt and flash the
|
||||
sky (on its server thread the host's window is a client of it too).
|
||||
- drops: an item lies where the host, then the guest, places a block: it comes out of the block
|
||||
on the server, and both sides see it outside (#1252).
|
||||
- underwater: the host and the guest each dig dirt by hand standing under water: five times slower
|
||||
than in the air on their own client as on the server, and it breaks (#1254).
|
||||
- worldspawn: the host moves the world spawn (`setworldspawn`): the host and the guest, with no bed,
|
||||
respawn there (#1310).
|
||||
- shield: a vindicator's axe disables the host's, then the guest's, raised shield: the server
|
||||
counts its 5 s cooldown down once a tick (#1316).
|
||||
- beds: the host and the guest each set their respawn point at a bed and die elsewhere: they
|
||||
stand up beside the bed, or, when the bed is gone or boxed in by stone, come back at
|
||||
the world spawn (#1308).
|
||||
- deathmining: the host and the guest each die while breaking obsidian and let go on the death
|
||||
screen: once respawned, the obsidian stays (#1315).
|
||||
- contacts: the host and the guest each stand on magma (and sneak on it), stand on a lit campfire,
|
||||
walk against a cactus and through grown sweet berry bushes: the server hurts them, but
|
||||
not the sneaking player or young bushes (#1305, #1311, #1312, #1313).
|
||||
- absorption: the host and the guest each take Absorption II and a hit of 3: their own HUD has the
|
||||
server's golden hearts, 8 then 5 (#1306).
|
||||
- breath: the host and the guest each stay underwater for 15 s in a Respiration III helmet: their
|
||||
own bubbles follow the server's air, which the enchantment makes last (#1304).
|
||||
- lava: (--server-thread) the host and the guest each stand in a Nether lava current with Fire
|
||||
Resistance, which pushes them at the Nether's strength (#1309).
|
||||
- flight: a player in creative double-taps jump and flies, stays up, and stops flying in survival:
|
||||
the guest, and on the server thread the host's window too, take what may fly from the
|
||||
server's abilities (ClientPacketListener.handlePlayerAbilities).
|
||||
@@ -187,7 +209,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', 'styles', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'hands', 'lightning', 'riding', 'mounts', 'levels']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'styles', 'commands', 'recipes', 'machines', 'brewing', 'loom', 'stonecutter', 'grindstone', 'anvil', 'smithing', 'enchanting', 'beacon', 'crafter', 'lectern', 'cartography', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight', 'ladder', 'boats', 'minecarts', 'frames', 'hands', 'lightning', 'riding', 'mounts', 'worldspawn', 'beds', 'shield', 'deathmining', 'contacts', 'absorption', 'breath', 'lava', 'levels', 'drops', 'underwater']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -2661,6 +2683,441 @@ def check_flight(host, guest, out):
|
||||
return seen
|
||||
|
||||
|
||||
def check_drops(host, guest, out):
|
||||
"""A dropped item lying where a block is then placed comes out of it (#1252): the server moves
|
||||
it towards the closest open side (ItemEntity.tick's noPhysics, Entity.moveTowardsClosestSpace),
|
||||
and both sides see it outside the block. The host places one, then the guest."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
seen = {}
|
||||
for game, dz in ((host, -3), (guest, 3)):
|
||||
x, y, z = hx + 3, hy, hz + dz
|
||||
game('command', command=f'fill {x - 1} {y} {z - 1} {x + 1} {y + 2} {z + 1} minecraft:air')
|
||||
game('command', command=f'summon minecraft:item {x + 0.5} {y} {z + 0.5} '
|
||||
'{Item:{id:"minecraft:diamond",count:1},PickupDelay:32767}')
|
||||
game.wait(20)
|
||||
game('command', command=f'setblock {x} {y} {z} minecraft:stone')
|
||||
game.wait(60)
|
||||
for viewer in (host, guest):
|
||||
near = [e['pos'] for e in viewer.raw('entities', 24, 'minecraft:item')['entities']
|
||||
if abs(e['pos'][0] - x - 0.5) < 2 and abs(e['pos'][2] - z - 0.5) < 2]
|
||||
seen[f'{game.name} places, {viewer.name} sees'] = ([x, y, z], near)
|
||||
game.shot(out, 'drops')
|
||||
host('command', command='kill @e[type=minecraft:item]')
|
||||
host('command', command=f'setblock {x} {y} {z} minecraft:air')
|
||||
for name, (block, near) in seen.items():
|
||||
inside = [p for p in near if all(block[i] <= p[i] < block[i] + 1 for i in range(3))]
|
||||
assert near and not inside, f'{name}: items {near} in block {block} (all: {seen})'
|
||||
return seen
|
||||
|
||||
|
||||
def check_underwater(host, guest, out):
|
||||
"""Digging dirt by hand underwater, standing on the bottom of a pool: five times slower than in
|
||||
the air (SUBMERGED_MINING_SPEED), on the player's own client as on the server. Halfway through
|
||||
the client is about halfway (it doesn't break the block early, which the server would put
|
||||
back), and the block breaks (#1254). The dirt is at eye height, the player's head under water.
|
||||
The host, then the guest."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
seen = {}
|
||||
for game, dz in ((host, -4), (guest, 4)):
|
||||
x, y, z = hx + 3, hy, hz + dz
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='item replace entity @s weapon.mainhand with minecraft:air')
|
||||
game('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 2} {y + 3} {z + 1} minecraft:stone')
|
||||
game('command', command=f'fill {x} {y} {z} {x} {y + 2} {z} minecraft:water')
|
||||
game('command', command=f'setblock {x + 1} {y + 1} {z} minecraft:dirt')
|
||||
game('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
|
||||
game.wait(40)
|
||||
game.raw('look-at', f'{x + 1.5:.2f}', f'{y + 1.5:.2f}', f'{z + 0.5:.2f}')
|
||||
game.wait(5)
|
||||
game.raw('mouse', 'left', 'down')
|
||||
# Dirt by hand: 15 ticks in the air, 75 under water.
|
||||
game.wait(35)
|
||||
halfway = {'mining': game('state').get('mining'), 'client': game.raw('block', x + 1, y + 1, z).get('block'),
|
||||
'server': host.raw('block', x + 1, y + 1, z).get('block'), 'y': y + 1}
|
||||
game.wait(70)
|
||||
game.raw('mouse', 'left', 'up')
|
||||
game.wait(10)
|
||||
done = host.raw('block', x + 1, y + 1, z).get('block')
|
||||
game.shot(out, 'underwater')
|
||||
seen[game.name] = {'halfway': halfway, 'done': done}
|
||||
host('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 2} {y + 3} {z + 1} minecraft:air')
|
||||
host('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 2} {y - 1} {z + 1} minecraft:stone')
|
||||
for name, s in seen.items():
|
||||
h = s['halfway']
|
||||
assert h['client'] == 'minecraft:dirt' == h['server'], f'{name} broke it early: {seen}'
|
||||
assert h['mining'] and h['mining']['pos'][1] == h['y'] and 0.3 < h['mining']['progress'] < 0.7, f'{name} digs at the wrong speed: {seen}'
|
||||
# Broken: air, or the pool's water flowing in.
|
||||
assert s['done'] in ('minecraft:air', 'minecraft:water'), f'{name} never broke it: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def own(game):
|
||||
"""The player's own state, as its client has it."""
|
||||
return game('state')['player']
|
||||
|
||||
|
||||
|
||||
|
||||
def check_contacts(host, guest, out):
|
||||
"""Blocks that hurt what touches them, on the server: standing on magma (but not sneaking on it)
|
||||
and on a lit campfire, walking against a cactus and through grown sweet berry bushes, for the
|
||||
host and the guest (#1305, #1311, #1312, #1313); a young bush pricks no one."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
host('command', command='gamerule natural_health_regeneration false')
|
||||
seen = {}
|
||||
try:
|
||||
for game, dz in ((host, -4), (guest, 4)):
|
||||
x, y, z = hx + 2, hy, hz + dz
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='effect clear @s')
|
||||
for case, blocks, walk in (
|
||||
('magma', [(0, -1, 'minecraft:magma_block')], False),
|
||||
('sneaking', [(0, -1, 'minecraft:magma_block')], False),
|
||||
('campfire', [(0, 0, 'minecraft:campfire[lit=true]')], False),
|
||||
('cactus', [(2, -1, 'minecraft:sand'), (2, 0, 'minecraft:cactus')], True),
|
||||
('berries', [(k, -1, 'minecraft:grass_block') for k in range(1, 4)]
|
||||
+ [(k, 0, 'minecraft:sweet_berry_bush[age=3]') for k in range(1, 4)], True),
|
||||
('young', [(k, -1, 'minecraft:grass_block') for k in range(1, 4)]
|
||||
+ [(k, 0, 'minecraft:sweet_berry_bush[age=0]') for k in range(1, 4)], True)):
|
||||
game('command', command='effect give @s minecraft:instant_health 1 5 true')
|
||||
game('command', command=f'fill {x - 1} {y - 2} {z - 1} {x + 4} {y - 1} {z + 1} minecraft:stone')
|
||||
game('command', command=f'fill {x - 1} {y} {z - 1} {x + 4} {y + 2} {z + 1} minecraft:air')
|
||||
# A wall ends the walk before the player leaves the floor.
|
||||
game('command', command=f'fill {x + 5} {y - 1} {z - 1} {x + 5} {y + 2} {z + 1} minecraft:stone')
|
||||
for dx, dy, block in blocks:
|
||||
game('command', command=f'setblock {x + dx} {y + dy} {z} {block}')
|
||||
stand = 0.5 if case == 'campfire' else 0.0
|
||||
# Sneaking from before the player lands on the magma.
|
||||
held = ['shift'] if case == 'sneaking' else []
|
||||
for k in held:
|
||||
game.raw('key', k, 'down')
|
||||
game.wait(5)
|
||||
game('command', command=f'tp @s {x + 0.5} {y + stand} {z + 0.5}')
|
||||
game.raw('look-at', f'{x + 10:.2f}', f'{y + 1.6:.2f}', f'{z + 0.5:.2f}')
|
||||
game.wait(30)
|
||||
before = own(game)['health']
|
||||
keys = ['w'] if walk else []
|
||||
for k in keys:
|
||||
game.raw('key', k, 'down')
|
||||
game.wait(60)
|
||||
# Read before letting go: standing up on the magma would hurt.
|
||||
after = own(game)['health']
|
||||
for k in keys + held:
|
||||
game.raw('key', k, 'up')
|
||||
game.wait(10)
|
||||
seen[f'{game.name}-{case}'] = (before, after)
|
||||
game.shot(out, f'contacts-{case}')
|
||||
host('command', command=f'fill {x - 1} {y} {z - 1} {x + 5} {y + 2} {z + 1} minecraft:air')
|
||||
finally:
|
||||
host('command', command='gamerule natural_health_regeneration true')
|
||||
for case, (before, after) in seen.items():
|
||||
safe = case.endswith(('sneaking', 'young'))
|
||||
assert (after == before) if safe else (after < before), f'{case}: {before} -> {after} (all: {seen})'
|
||||
return seen
|
||||
|
||||
|
||||
def server_player(host, game):
|
||||
"""The player's entry on the server: the guest's in the host's `lan status`, on the server
|
||||
thread the host's too; the host's own world otherwise."""
|
||||
if game is host and not SERVER_THREAD:
|
||||
return own(host)
|
||||
name = GUEST_NAME if game is not host else host.player
|
||||
return next(g for g in host.raw('lan', 'status')['guests'] if g['name'] == name)
|
||||
|
||||
|
||||
def check_shield(host, guest, out):
|
||||
"""An axe disables a raised shield for 5 s (100 ticks), counted down once a tick on the
|
||||
server: a vindicator's axe hits each player's shield, then the cooldown left falls by about 40
|
||||
over 40 ticks (#1316)."""
|
||||
host('command', command='gamerule natural_health_regeneration false')
|
||||
rates = {}
|
||||
try:
|
||||
for game, dz in ((host, -4), (guest, 4)):
|
||||
x, y, z = (int(v // 1) for v in pos_of(host))
|
||||
z += dz
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='effect give @s minecraft:resistance 60 4 true')
|
||||
game('command', command='effect give @s minecraft:instant_health 1 5 true')
|
||||
game('command', command='item replace entity @s weapon.mainhand with minecraft:air')
|
||||
game('command', command='item replace entity @s weapon.offhand with minecraft:shield')
|
||||
game('command', command=f'fill {x - 1} {y} {z - 1} {x + 4} {y + 2} {z + 1} minecraft:air')
|
||||
game('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 4} {y - 1} {z + 1} minecraft:stone')
|
||||
game('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
|
||||
game.wait(10)
|
||||
game.raw('look-at', f'{x + 2.5:.2f}', f'{y + 1.5:.2f}', f'{z + 0.5:.2f}')
|
||||
game.raw('mouse', 'right', 'down')
|
||||
game.wait(10)
|
||||
host('command', command=f'summon minecraft:vindicator {x + 2.5} {y} {z + 0.5} '
|
||||
'{PersistenceRequired:1b,Rotation:[90f,0f]}')
|
||||
host('command', command='item replace entity @e[type=minecraft:vindicator] weapon.mainhand '
|
||||
'with minecraft:iron_axe')
|
||||
first = None
|
||||
for _ in range(60):
|
||||
game.wait(5)
|
||||
first = server_player(host, game).get('shield_cooldown', 0)
|
||||
if first:
|
||||
break
|
||||
host('command', command='kill @e[type=minecraft:vindicator]')
|
||||
game.raw('mouse', 'right', 'up')
|
||||
assert first, f'{game.name}: the vindicator never disabled the shield'
|
||||
start = server_player(host, game)['shield_cooldown']
|
||||
game.wait(40)
|
||||
end = server_player(host, game)['shield_cooldown']
|
||||
rates[game.name] = {'first': first, 'start': start, 'end': end}
|
||||
game.shot(out, 'shield')
|
||||
game('command', command='item replace entity @s weapon.offhand with minecraft:air')
|
||||
game('command', command='effect clear @s')
|
||||
finally:
|
||||
host('command', command='kill @e[type=minecraft:vindicator]')
|
||||
host('command', command='gamerule natural_health_regeneration true')
|
||||
for name, r in rates.items():
|
||||
assert r['first'] <= 100, f'{name}: {rates}'
|
||||
# Once a tick: 40 down over 40 ticks, give or take the ticks the two queries straddle.
|
||||
assert 30 <= r['start'] - r['end'] <= 50, f'{name}: {rates}'
|
||||
return rates
|
||||
|
||||
|
||||
def respawn_when_ready(game):
|
||||
"""Press Respawn once the death screen lets it (DeathScreen's 20-tick delay, counted from when
|
||||
the screen opens)."""
|
||||
for _ in range(20):
|
||||
try:
|
||||
return game.raw('respawn')
|
||||
except Failed as e:
|
||||
if 'not active yet' not in str(e):
|
||||
raise
|
||||
game.wait(10)
|
||||
return game.raw('respawn')
|
||||
|
||||
|
||||
def check_world_spawn(host, guest, out):
|
||||
"""`setworldspawn` moves the world spawn: the host and the guest, with no bed of their own,
|
||||
respawn there once killed (#1310)."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
sx, sz = hx + 24, hz
|
||||
host('command', command='gamerule respawn_radius 0')
|
||||
host('command', command=f'fill {sx - 2} {hy - 1} {sz - 2} {sx + 2} {hy - 1} {sz + 2} minecraft:stone')
|
||||
host('command', command=f'fill {sx - 2} {hy} {sz - 2} {sx + 2} {hy + 3} {sz + 2} minecraft:air')
|
||||
seen = {}
|
||||
try:
|
||||
host('command', command=f'setworldspawn {sx} {hy} {sz}')
|
||||
for game in (host, guest):
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='kill @s')
|
||||
game.wait(20)
|
||||
respawn_when_ready(game)
|
||||
game.wait(60)
|
||||
seen[game.name] = [round(v, 2) for v in pos_of(game)]
|
||||
game.shot(out, 'world-spawn')
|
||||
finally:
|
||||
host('command', command=f'setworldspawn {hx} {hy} {hz}')
|
||||
host('command', command='gamerule respawn_radius 10')
|
||||
for game in (host, guest):
|
||||
game('command', command=f'tp @s {hx + 0.5} {hy} {hz + 0.5}')
|
||||
guest.wait(20)
|
||||
for name, at in seen.items():
|
||||
assert abs(at[0] - (sx + 0.5)) < 1 and abs(at[2] - (sz + 0.5)) < 1, f'{name}: {seen}, spawn {sx} {sz}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_beds(host, guest, out):
|
||||
"""A bed sets the respawn point (day or night): respawning stands the player up beside it; a bed
|
||||
that is gone, or boxed in by stone so there is nowhere to stand up, sends the player to the world
|
||||
spawn instead (#1308). The host, then the guest, each for the three beds."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
host('command', command='gamerule respawn_radius 0')
|
||||
host('command', command=f'setworldspawn {hx} {hy} {hz}')
|
||||
host('command', command='time set 1000')
|
||||
seen = {}
|
||||
try:
|
||||
for game, dz in ((host, -6), (guest, 6)):
|
||||
game('command', command='gamemode survival')
|
||||
x, y, z = hx + 12, hy, hz + dz
|
||||
for case in ('intact', 'gone', 'boxed'):
|
||||
game('command', command=f'fill {x - 3} {y - 1} {z - 3} {x + 4} {y - 1} {z + 3} minecraft:stone')
|
||||
game('command', command=f'fill {x - 3} {y} {z - 3} {x + 4} {y + 3} {z + 3} minecraft:air')
|
||||
game('command', command=f'setblock {x} {y} {z} minecraft:red_bed[facing=east,part=foot]')
|
||||
game('command', command=f'setblock {x + 1} {y} {z} minecraft:red_bed[facing=east,part=head]')
|
||||
game('command', command=f'tp @s {x + 0.5} {y} {z + 1.5}')
|
||||
game.wait(20)
|
||||
game.raw('interact', x + 1, y, z)
|
||||
game.wait(10)
|
||||
# Die elsewhere, by the world spawn.
|
||||
game('command', command=f'tp @s {hx + 0.5} {hy} {hz + 3.5}')
|
||||
game.wait(10)
|
||||
if case == 'gone':
|
||||
game('command', command=f'fill {x} {y} {z} {x + 1} {y} {z} minecraft:air')
|
||||
elif case == 'boxed':
|
||||
game('command', command=f'fill {x - 2} {y} {z - 2} {x + 3} {y + 2} {z + 2} minecraft:stone replace minecraft:air')
|
||||
game.wait(5)
|
||||
game('command', command='kill @s')
|
||||
game.wait(20)
|
||||
respawn_when_ready(game)
|
||||
game.wait(60)
|
||||
at = [round(v, 2) for v in pos_of(game)]
|
||||
seen[f'{game.name}-{case}'] = {'at': at, 'bed': [x + 1, y, z], 'health': own(game)['health']}
|
||||
game.shot(out, f'beds-{case}')
|
||||
finally:
|
||||
host('command', command='gamerule respawn_radius 10')
|
||||
host('command', command='time set 1000')
|
||||
for game in (host, guest):
|
||||
game('command', command=f'tp @s {hx + 0.5} {hy} {hz + 0.5}')
|
||||
guest.wait(20)
|
||||
for case, s in seen.items():
|
||||
(px, py, pz), (bx, by, bz) = s['at'], s['bed']
|
||||
if case.endswith('intact'):
|
||||
near = ((px - bx - 0.5) ** 2 + (pz - bz - 0.5) ** 2) ** 0.5
|
||||
assert near < 2.6 and abs(py - by) < 0.6, f'{case}: not beside its bed: {seen}'
|
||||
else:
|
||||
assert abs(px - (hx + 0.5)) < 1 and abs(pz - (hz + 0.5)) < 1, f'{case}: not at the world spawn: {seen}'
|
||||
assert s['health'] > 0, f'{case}: died again after respawning: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_death_mining(host, guest, out):
|
||||
"""A player who dies while breaking obsidian, and lets go of attack on the death screen, doesn't
|
||||
break it once respawned: death forgets the digging (#1315)."""
|
||||
host('command', command='gamerule keep_inventory true')
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
seen = {}
|
||||
try:
|
||||
for game, dz in ((host, -3), (guest, 3)):
|
||||
x, y, z = hx + 2, hy, hz + dz
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='item replace entity @s weapon.mainhand with minecraft:diamond_pickaxe')
|
||||
game('command', command=f'setblock {x + 2} {y} {z} minecraft:obsidian')
|
||||
game('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
|
||||
game.wait(10)
|
||||
game.raw('look-at', f'{x + 2.5:.2f}', f'{y + 0.5:.2f}', f'{z + 0.5:.2f}')
|
||||
game.wait(5)
|
||||
game.raw('mouse', 'left', 'down')
|
||||
game.wait(10)
|
||||
game('command', command='kill @s')
|
||||
game.wait(10)
|
||||
# The death screen lets go of the button (Minecraft.setScreen); let go again once back.
|
||||
try:
|
||||
game.raw('mouse', 'left', 'up')
|
||||
except Failed:
|
||||
pass
|
||||
game.wait(10)
|
||||
respawn_when_ready(game)
|
||||
game.wait(2)
|
||||
try:
|
||||
game.raw('mouse', 'left', 'up')
|
||||
except Failed:
|
||||
pass
|
||||
# Obsidian takes a diamond pickaxe about 190 ticks.
|
||||
game.wait(240)
|
||||
seen[game.name] = host.raw('block', x + 2, y, z).get('block')
|
||||
game.shot(out, 'death-mining')
|
||||
host('command', command=f'setblock {x + 2} {y} {z} minecraft:air')
|
||||
game('command', command='item replace entity @s weapon.mainhand with minecraft:air')
|
||||
finally:
|
||||
host('command', command='gamerule keep_inventory false')
|
||||
for name, block in seen.items():
|
||||
assert block == 'minecraft:obsidian', f'{name}: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_absorption(host, guest, out):
|
||||
"""Absorption II's golden hearts on each player's own HUD: 8 of them, and 5 once a hit of 3 took
|
||||
its share: the client shows what the server's player has (#1306)."""
|
||||
seen = {}
|
||||
for game in (host, guest):
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='effect give @s minecraft:absorption 120 1')
|
||||
game.wait(10)
|
||||
given = own(game)['absorption']
|
||||
game('command', command='damage @s 3 minecraft:generic')
|
||||
game.wait(20)
|
||||
me = own(game)
|
||||
server = server_player(host, game)
|
||||
game.shot(out, 'absorption')
|
||||
game('command', command='effect clear @s minecraft:absorption')
|
||||
seen[game.name] = {'given': given, 'left': me['absorption'], 'health': me['health'],
|
||||
'server': server.get('absorption')}
|
||||
for name, s in seen.items():
|
||||
assert s['given'] == 8.0 and s['left'] == 5.0 == s['server'] and s['health'] == 20.0, \
|
||||
f'{name}: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_breath(host, guest, out):
|
||||
"""Underwater in a Respiration III helmet for 15 s: the enchantment makes the air last on the
|
||||
server, and each player's own bubbles follow the server's air (#1304)."""
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
seen = {}
|
||||
for game, dz in ((host, -4), (guest, 4)):
|
||||
x, y, z = hx + 3, hy, hz + dz
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command='item replace entity @s armor.head with '
|
||||
'minecraft:diamond_helmet[minecraft:enchantments={"minecraft:respiration":3}]')
|
||||
game('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 1} {y + 2} {z + 1} minecraft:stone')
|
||||
game('command', command=f'fill {x} {y} {z} {x} {y + 1} {z} minecraft:water')
|
||||
game('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
|
||||
host.wait(300)
|
||||
for game in (host, guest):
|
||||
game.shot(out, 'breath')
|
||||
seen[game.name] = {'own': own(game)['air'], 'server': server_player(host, game).get('air')}
|
||||
for game, dz in ((host, -4), (guest, 4)):
|
||||
x, y, z = hx + 3, hy, hz + dz
|
||||
game('command', command='item replace entity @s armor.head with minecraft:air')
|
||||
host('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 1} {y + 2} {z + 1} minecraft:air')
|
||||
host('command', command=f'fill {x - 1} {y - 1} {z - 1} {x + 1} {y - 1} {z + 1} minecraft:stone')
|
||||
guest.wait(40)
|
||||
# 300 ticks lose about 75 of the 300 with Respiration III, all of it without.
|
||||
for name, s in seen.items():
|
||||
assert s['server'] > 150 and abs(s['own'] - s['server']) <= 10, f'{name}: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_lava(host, guest, out):
|
||||
"""(--server-thread) Standing in a settled Nether lava current with Fire Resistance: the
|
||||
Nether's FAST_LAVA pushes each player about three times as hard as the Overworld's (#1309)."""
|
||||
if not SERVER_THREAD:
|
||||
return 'skipped (needs --server-thread)'
|
||||
seen = {}
|
||||
back = {g.name: pos_of(g) for g in (host, guest)}
|
||||
try:
|
||||
for game, z in ((host, 0), (guest, 6)):
|
||||
game('command', command=f'execute in minecraft:the_nether run tp @s 0.5 100 {z + 0.5}')
|
||||
state = wait_dimension(game, 'minecraft:the_nether', 600)
|
||||
assert state.get('dimension') == 'minecraft:the_nether', f'{game.name} is in {state.get("dimension")}'
|
||||
game.wait(40)
|
||||
# A one-wide obsidian channel along x: a source at x = -3, the current flowing east.
|
||||
game('command', command=f'fill -5 98 {z - 2} 6 104 {z + 2} minecraft:air')
|
||||
game('command', command=f'fill -5 98 {z - 1} 6 98 {z + 1} minecraft:obsidian')
|
||||
game('command', command=f'fill -5 99 {z - 1} 6 99 {z - 1} minecraft:obsidian')
|
||||
game('command', command=f'fill -5 99 {z + 1} 6 99 {z + 1} minecraft:obsidian')
|
||||
game('command', command=f'fill -4 99 {z} -4 99 {z} minecraft:obsidian')
|
||||
game('command', command='effect give @s minecraft:fire_resistance 120 0 true')
|
||||
game('command', command='gamemode survival')
|
||||
game('command', command=f'setblock -3 99 {z} minecraft:lava')
|
||||
host.wait(100)
|
||||
for game, z in ((host, 0), (guest, 6)):
|
||||
game('command', command=f'tp @s 0.5 99 {z + 0.5}')
|
||||
host.wait(60)
|
||||
for game, z in ((host, 0), (guest, 6)):
|
||||
v = own(game)['velocity']
|
||||
seen[game.name] = {'vx': v[0], 'level': game.raw('block', 0, 99, z).get('state')}
|
||||
game.shot(out, 'lava')
|
||||
finally:
|
||||
for game, z in ((host, 0), (guest, 6)):
|
||||
host('command', command=f'execute in minecraft:the_nether run fill -5 98 {z - 2} 6 104 {z + 2} minecraft:air')
|
||||
x, y, zz = back[game.name]
|
||||
game('command', command='effect clear @s minecraft:fire_resistance')
|
||||
game('command', command=f'execute in minecraft:overworld run tp @s {x:.2f} {y:.2f} {zz:.2f}')
|
||||
for game in (host, guest):
|
||||
wait_dimension(game, 'minecraft:overworld', 600)
|
||||
guest.wait(40)
|
||||
# The Overworld's current settles at about 0.0047 a tick, the Nether's at about 0.014.
|
||||
for name, s in seen.items():
|
||||
assert s['vx'] > 0.009, f'{name}: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_ladder(host, guest, out):
|
||||
"""#1255: climbing down a ladder doesn't hurt where the guest lands."""
|
||||
@@ -3492,33 +3949,32 @@ def check_worn(host, guest, out):
|
||||
return taken
|
||||
|
||||
|
||||
CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'nametags': check_nametags,
|
||||
'chest': check_chest, 'crafting': check_crafting, 'sign': check_sign, 'damage': check_damage,
|
||||
'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp,
|
||||
'respawn': check_respawn,
|
||||
'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles, 'chat': check_chat, 'styles': check_styles,
|
||||
'machines': check_machines,
|
||||
'brewing': check_brewing,
|
||||
'loom': check_loom,
|
||||
'stonecutter': check_stonecutter,
|
||||
'grindstone': check_grindstone,
|
||||
'anvil': check_anvil,
|
||||
'smithing': check_smithing,
|
||||
'enchanting': check_enchanting,
|
||||
'beacon': check_beacon,
|
||||
'crafter': check_crafter,
|
||||
'lectern': check_lectern,
|
||||
'cartography': check_cartography,
|
||||
'hurt': check_hurt,
|
||||
'commands': check_commands,
|
||||
CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour,
|
||||
'nametags': check_nametags, 'chest': check_chest, 'crafting': check_crafting,
|
||||
'sign': check_sign, 'damage': check_damage, 'mobs': check_mobs,
|
||||
'hazards': check_hazards, 'pvp': check_pvp, 'respawn': check_respawn,
|
||||
'containers': check_containers, 'feedback': check_feedback, 'titles': check_titles,
|
||||
'chat': check_chat, 'styles': check_styles, 'machines': check_machines, 'brewing': check_brewing,
|
||||
'loom': check_loom, 'stonecutter': check_stonecutter, 'grindstone': check_grindstone,
|
||||
'anvil': check_anvil, 'smithing': check_smithing, 'enchanting': check_enchanting,
|
||||
'beacon': check_beacon, 'crafter': check_crafter, 'lectern': check_lectern,
|
||||
'cartography': check_cartography, 'hurt': check_hurt, 'commands': check_commands,
|
||||
'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls,
|
||||
'effects': check_effects, 'portals': check_portals, 'distance': check_distance, 'clicks': check_clicks,
|
||||
'sleep': check_sleep, 'push': check_push, 'eat': check_eat, 'eating': check_eating,
|
||||
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles, 'blast': check_blast,
|
||||
'light': check_light, 'plates': check_plates,
|
||||
'swings': check_swings, 'cracks': check_cracks,
|
||||
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder, 'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'hands': check_hands, 'lightning': check_lightning, 'riding': check_riding, 'mounts': check_mounts,
|
||||
'levels': check_levels}
|
||||
'effects': check_effects, 'portals': check_portals, 'distance': check_distance,
|
||||
'clicks': check_clicks, 'sleep': check_sleep, 'push': check_push,
|
||||
'eat': check_eat, 'eating': check_eating, 'xp': check_xp,
|
||||
'objects': check_objects, 'projectiles': check_projectiles, 'blast': check_blast,
|
||||
'light': check_light, 'plates': check_plates, 'swings': check_swings,
|
||||
'cracks': check_cracks, 'time': check_time, 'growth': check_growth,
|
||||
'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect,
|
||||
'barter': check_barter, 'worn': check_worn, 'kills': check_kills,
|
||||
'arrows': check_arrows, 'predict': check_predict, 'ladder': check_ladder,
|
||||
'boats': check_boats, 'minecarts': check_minecarts, 'frames': check_frames, 'hands': check_hands,
|
||||
'lightning': check_lightning, 'riding': check_riding, 'mounts': check_mounts,
|
||||
'worldspawn': check_world_spawn, 'beds': check_beds, 'shield': check_shield, 'deathmining': check_death_mining,
|
||||
'contacts': check_contacts, 'absorption': check_absorption, 'breath': check_breath,
|
||||
'lava': check_lava, 'levels': check_levels, 'drops': check_drops,
|
||||
'underwater': check_underwater}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
+36
-13
@@ -256,6 +256,23 @@ def write_options(game_dir, distance, version=None):
|
||||
return text
|
||||
|
||||
|
||||
# Window sizes of the standard set (every game gets --width/--height): 720p,
|
||||
# the size results were first published at, and 1080p, the commonest screen.
|
||||
SIZES = [(1280, 720), (1920, 1080)]
|
||||
|
||||
|
||||
def parse_sizes(text):
|
||||
""""1280x720,1920x1080" as [(1280, 720), (1920, 1080)]."""
|
||||
return [tuple(int(v) for v in size.lower().split("x")) for size in text.split(",") if size]
|
||||
|
||||
|
||||
def size_label(label, width, height):
|
||||
"""Reports at 1280x720 keep the plain label; other sizes add theirs: horizon-m4-1080p, or -2560x1080."""
|
||||
if (width, height) == SIZES[0]:
|
||||
return label
|
||||
return f"{label}-{height}p" if width * 9 == height * 16 else f"{label}-{width}x{height}"
|
||||
|
||||
|
||||
def scene_list(args):
|
||||
picked = args.scenes.split(",") if args.scenes else [s[0] for s in SCENES]
|
||||
return [s for s in SCENES if s[0] in picked]
|
||||
@@ -375,6 +392,9 @@ def run_horizon(args, distance):
|
||||
client = Path(args.build).resolve() / "horizon-client"
|
||||
command = [str(client), "--resources", str(Path(args.resources).resolve()),
|
||||
"--control-socket", str(sock), "--no-pause", "--weather", "clear", "--time", "6000"]
|
||||
if (args.width, args.height) != SIZES[0]:
|
||||
# 1280x720 is Horizon's own window; builds before --width open only that one.
|
||||
command += ["--width", str(args.width), "--height", str(args.height)]
|
||||
if args.offscreen:
|
||||
command.append("--offscreen")
|
||||
for carry in dev_mods(args):
|
||||
@@ -796,8 +816,8 @@ def main():
|
||||
p.add_argument("--seconds", type=float, default=12.0, help="flight duration per scene")
|
||||
p.add_argument("--settle", type=float, default=2.0, help="seconds held at the start before each flight")
|
||||
p.add_argument("--timeout", type=float, default=300.0, help="seconds allowed for each load")
|
||||
p.add_argument("--width", type=int, default=1280, help="vanilla window width (Horizon's is 1280x720)")
|
||||
p.add_argument("--height", type=int, default=720)
|
||||
p.add_argument("--sizes", default=",".join(f"{w}x{h}" for w, h in SIZES),
|
||||
help="window sizes, each a set of reports (default 1280x720 and 1920x1080)")
|
||||
p.add_argument("--heap", default="2G", help="vanilla -Xmx (the official launcher's default is 2G)")
|
||||
p.add_argument("--offscreen", action="store_true",
|
||||
help="Horizon renders into a texture and does not wait for the window (locked macOS sessions)")
|
||||
@@ -817,17 +837,20 @@ def main():
|
||||
args.label = args.label or f"{args.game}-{platform.node().split('.')[0]}"
|
||||
WORK.mkdir(parents=True, exist_ok=True)
|
||||
run = {"horizon": run_horizon, "neoforge": run_neoforge}.get(args.game, run_vanilla)
|
||||
for d in [int(x) for x in args.distances.split(",")]:
|
||||
runs = []
|
||||
for _ in range(args.repeats):
|
||||
load_before = os.getloadavg()
|
||||
result = run(args, d)
|
||||
result["load_before"], result["load_after"] = load_before, os.getloadavg()
|
||||
runs.append(result)
|
||||
out = ROOT / "benchmarks/perf" / f"{args.label}-rd{d}.json"
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
out.write_text(json.dumps(report(args, d, runs, app(args)), indent=1) + "\n")
|
||||
print(out)
|
||||
label = args.label
|
||||
for args.width, args.height in parse_sizes(args.sizes):
|
||||
args.label = size_label(label, args.width, args.height)
|
||||
for d in [int(x) for x in args.distances.split(",")]:
|
||||
runs = []
|
||||
for _ in range(args.repeats):
|
||||
load_before = os.getloadavg()
|
||||
result = run(args, d)
|
||||
result["load_before"], result["load_after"] = load_before, os.getloadavg()
|
||||
runs.append(result)
|
||||
out = ROOT / "benchmarks/perf" / f"{args.label}-rd{d}.json"
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
out.write_text(json.dumps(report(args, d, runs, app(args)), indent=1) + "\n")
|
||||
print(out)
|
||||
|
||||
|
||||
def app(args):
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare how a client walks a living entity along its server's positions with vanilla.
|
||||
|
||||
Vanilla's unmodified SteppedInterpolationHandler.InterpolationData (VanillaSteppedInterpolationOracle
|
||||
drives it as the handler does) and horizon-world's SteppedInterpolation replay the same packets and
|
||||
client ticks: move packets with and without a position or rotation, straight or stepped paths,
|
||||
repeats of the one the entity is headed for, packets a tick apart that pile up and others after it
|
||||
stopped, for update intervals of 1 to 3 ticks, plus a punched pig's knockback as the server sends it
|
||||
(its first move at once, `needsSync`, then every update interval). The entity's position and rotation
|
||||
after every event must match bit for bit. The handler's entity hooks (deltas, passengers) are out of
|
||||
scope.
|
||||
"""
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
try:
|
||||
from . import lab, test_rust_parity as base
|
||||
except ImportError:
|
||||
import lab
|
||||
import test_rust_parity as base
|
||||
|
||||
# A pig punched on flat ground, its positions on the server tick by tick (knockback 0.4 along x).
|
||||
KNOCKBACK = [(0.0, 0.0), (0.3032, 0.3608), (0.4638, 0.636), (0.6049, 0.8273), (0.7279, 0.9363), (0.8345, 0.9648),
|
||||
(0.926, 0.9143), (1.0037, 0.7864), (1.0688, 0.5827), (1.1223, 0.3046), (1.1654, 0.0), (1.1147, 0.0),
|
||||
(0.9968, 0.0), (0.8418, 0.0), (0.6664, 0.0)]
|
||||
|
||||
|
||||
def position(rng, p):
|
||||
return [round(v + rng.uniform(-0.6, 0.6), rng.choice([2, 4, 17])) for v in p]
|
||||
|
||||
|
||||
def rotation(rng):
|
||||
return [round(rng.uniform(-400, 400), rng.choice([0, 1, 3])), round(rng.uniform(-120, 120), rng.choice([0, 2]))]
|
||||
|
||||
|
||||
def cases(count, seed):
|
||||
rng = random.Random(seed)
|
||||
lines = []
|
||||
for interval in (1, 2, 3):
|
||||
# The knockback: a packet for the hit tick's move, then every interval (each phase).
|
||||
for phase in range(interval):
|
||||
lines.append(f'case {interval} 10.5 64.0 0.5 90.0 0.0')
|
||||
for k in range(1, len(KNOCKBACK)):
|
||||
if k == 1 or (k + phase) % interval == 0:
|
||||
x, y = KNOCKBACK[k]
|
||||
lines.append(f'move L {10.5 + x!r} {64 + y!r} 0.5 -')
|
||||
lines.append('tick')
|
||||
lines += ['tick'] * 6
|
||||
for _ in range(count):
|
||||
p = [rng.uniform(-100, 100), rng.uniform(-64, 300), rng.uniform(-100, 100)]
|
||||
yaw, pitch = rotation(rng)
|
||||
lines.append(f'case {rng.choice([1, 2, 3, 3, 3])} {p[0]!r} {p[1]!r} {p[2]!r} {yaw!r} {pitch!r}')
|
||||
last = None
|
||||
for _ in range(rng.randrange(1, 40)):
|
||||
if rng.random() < 0.45:
|
||||
lines.append('tick')
|
||||
continue
|
||||
if last is not None and rng.random() < 0.15:
|
||||
line = last # the same packet again
|
||||
else:
|
||||
if rng.random() < 0.1:
|
||||
line = 'move N'
|
||||
elif rng.random() < 0.2:
|
||||
n = rng.randrange(1, 5)
|
||||
steps = []
|
||||
for _ in range(n):
|
||||
p = position(rng, p)
|
||||
steps.append(f'{p[0]!r} {p[1]!r} {p[2]!r} {rng.randrange(1, 4)}')
|
||||
line = f'move S {n} ' + ' '.join(steps)
|
||||
else:
|
||||
p = position(rng, p) if rng.random() < 0.9 else p
|
||||
line = f'move L {p[0]!r} {p[1]!r} {p[2]!r}'
|
||||
rot = rotation(rng) if rng.random() < 0.6 else None
|
||||
line += f' R {rot[0]!r} {rot[1]!r}' if rot else ' -'
|
||||
last = line
|
||||
lines.append(line)
|
||||
lines += ['tick'] * rng.choice([0, 1, 1, 2, 3, 6])
|
||||
return lines
|
||||
|
||||
|
||||
def main():
|
||||
lock, jars, libraries = base.verify_artifacts()
|
||||
build = lab.LOCAL / 'stepped-interpolation-parity'
|
||||
build.mkdir(parents=True, exist_ok=True)
|
||||
classes = build / 'classes'
|
||||
classes.mkdir(exist_ok=True)
|
||||
events = build / 'events.txt'
|
||||
events.write_text('\n'.join(cases(3000, 1374)) + '\n', encoding='utf-8')
|
||||
classpath = os.pathsep.join(map(str, [jars['client'], *libraries]))
|
||||
oracle = lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSteppedInterpolationOracle.java'
|
||||
subprocess.run(['javac', '--release', str(lock['minecraft']['java_major']), '-proc:none',
|
||||
'-cp', classpath, '-d', str(classes), str(oracle)], check=True)
|
||||
subprocess.run(['java', '-Xmx512M', '-cp', str(classes) + os.pathsep + classpath,
|
||||
'dev.horizonlab.parity.VanillaSteppedInterpolationOracle', str(events), str(build / 'vanilla.txt')],
|
||||
check=True)
|
||||
subprocess.run(['cargo', 'run', '--quiet', '--release', '-p', 'horizon-world', '--example',
|
||||
'stepped_interpolation_fixture', '--', str(events), str(build / 'rust.txt')], cwd=lab.ROOT, check=True)
|
||||
matched = base.compare(build / 'vanilla.txt', build / 'rust.txt')
|
||||
print(f'Stepped interpolation parity passed: {matched} entity positions and rotations match vanilla')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -23,7 +23,9 @@ explode elsewhere (`RespawnAnchorBlock`, through the stand-in level's real
|
||||
`ServerExplosion`, with water at the anchor). Respawn cases call
|
||||
`ServerPlayer.findRespawnAndUseSpawnBlock` on an anchor among blocks
|
||||
(`RespawnAnchorBlock.findStandUpPosition` through `DismountHelper`): the
|
||||
position, the yaw that faces the anchor and the charge it uses. Beds and straw
|
||||
position, the yaw that faces the anchor and the charge it uses; others on a
|
||||
bed's head set from some yaw (`AbstractBedBlock.findStandUpPosition`: intact,
|
||||
bunk, only the foot left or gone, crowded around and on top). Beds and straw
|
||||
beds clicked (head or foot, whole or broken) in the Nether and the End blow up
|
||||
or fall apart (`AbstractBedBlock.useWithoutItem` under the dimension's
|
||||
`bed_rule`: `BedBlock.destroyOnUse`, `StrawBedBlock.destroyBed`). Horizon runs
|
||||
@@ -90,6 +92,52 @@ BED_COLORS = ['red', 'white', 'black', 'cyan', 'lime']
|
||||
FACINGS = {'north': (0, -1), 'south': (0, 1), 'west': (-1, 0), 'east': (1, 0)}
|
||||
|
||||
|
||||
def bed_respawn_case(rng, states, case):
|
||||
"""Respawning at a bed's head set from some yaw: intact, a bunk bed, only the foot left or
|
||||
gone, with blocks around and on it, in the Overworld (and a few in the Nether or the End)."""
|
||||
name = 'straw_bed' if rng.random() < 0.15 else rng.choice(BED_COLORS) + '_bed'
|
||||
facing = rng.choice(list(FACINGS))
|
||||
fx, fz = FACINGS[facing]
|
||||
bed = {}
|
||||
kept = rng.random()
|
||||
if kept < 0.75:
|
||||
bed[(0, 0, 0)] = states.get(name, facing=facing, part='head', occupied='false')
|
||||
elif kept < 0.85:
|
||||
bed[(0, 0, 0)] = states.get(rng.choice(['stone', 'white_carpet', 'oak_slab']))
|
||||
if kept < 0.9 or rng.random() < 0.5:
|
||||
bed[(-fx, 0, -fz)] = states.get(name, facing=facing, part='foot', occupied='false')
|
||||
if rng.random() < 0.2:
|
||||
# A bunk bed: another bed below.
|
||||
bed[(0, -1, 0)] = states.get(name, facing=facing, part='head', occupied='false')
|
||||
bed[(-fx, -1, -fz)] = states.get(name, facing=facing, part='foot', occupied='false')
|
||||
crowd = rng.choice([0.0, 0.1, 0.3, 0.6, 0.95])
|
||||
cells = [[*k, v] for k, v in bed.items()]
|
||||
if (0, 0, 0) not in bed:
|
||||
cells.insert(0, [0, 0, 0, states.get('air')])
|
||||
for dy in (-2, -1, 0, 1, 2):
|
||||
for dx in range(-3, 4):
|
||||
for dz in range(-3, 4):
|
||||
if (dx, dy, dz) in bed or (dx, dy, dz) == (0, 0, 0):
|
||||
continue
|
||||
if dy == -1 and (dx, 0, dz) in bed:
|
||||
name2 = 'stone'
|
||||
elif dy < 0:
|
||||
name2 = rng.choice(['stone'] * 8 + STAND)
|
||||
elif rng.random() < crowd:
|
||||
name2 = rng.choice(['stone'] * 4 + STAND)
|
||||
else:
|
||||
continue
|
||||
if name2 == 'air':
|
||||
continue
|
||||
state = states.any(rng, name2) if name2 in ('oak_trapdoor', 'oak_slab', 'snow', 'campfire', 'water', 'ladder') else states.get(name2)
|
||||
cells.append([dx, dy, dz, state])
|
||||
if rng.random() < 0.1:
|
||||
case['dim'] = rng.choice(['nether', 'end'])
|
||||
yaw = rng.choice([0.0, 90.0, -90.0, 180.0, round(rng.uniform(-720, 720), rng.choice([0, 2]))])
|
||||
case['respawn_at'] = {'forced': rng.random() < 0.15, 'consume': rng.random() < 0.8, 'yaw': yaw}
|
||||
case['cells'] = cells
|
||||
|
||||
|
||||
def bed_case(rng, states, case):
|
||||
"""A bed (or straw bed) clicked in the Nether or the End, among blocks."""
|
||||
name = 'straw_bed' if rng.random() < 0.25 else rng.choice(BED_COLORS) + '_bed'
|
||||
@@ -224,6 +272,12 @@ def cases(facts, count, seed):
|
||||
case['mode'] = 'dispense'
|
||||
yield case
|
||||
continue
|
||||
if rng.random() < 0.1:
|
||||
bed_respawn_case(rng, states, case)
|
||||
case['items'] = []
|
||||
case['mode'] = 'dispense'
|
||||
yield case
|
||||
continue
|
||||
if rng.random() < 0.15:
|
||||
anchor_case(rng, states, case)
|
||||
case['items'] = []
|
||||
|
||||
Reference in New Issue
Block a user