Minecraft: Update to new options system. (#3765)

* Move to new options system.
switch to using self.random
reformat rules file.

* further reformats

* fix tests to use new options system.

* fix slot data to not use self.multiworld

* I hate python

* new starting_items docstring to prepare for 1.20.5+ item components.
fix invalid json being output to starting_items

* more typing fixes.

* stupid quotes around type declarations

* removed unused variable in ItemPool.py
change null check in Structures.py

* update rules "self" variable to a "world: MinecraftWorld" variable

* get key, and not value for required bosses.
This commit is contained in:
KonoTyran
2024-08-19 15:58:30 -07:00
committed by GitHub
parent 1e8a8e7482
commit c010c8c938
7 changed files with 517 additions and 308 deletions

View File

@@ -1,17 +1,19 @@
from worlds.AutoWorld import World
from . import Constants
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from . import MinecraftWorld
def shuffle_structures(mc_world: World) -> None:
multiworld = mc_world.multiworld
player = mc_world.player
def shuffle_structures(self: "MinecraftWorld") -> None:
multiworld = self.multiworld
player = self.player
default_connections = Constants.region_info["default_connections"]
illegal_connections = Constants.region_info["illegal_connections"]
# Get all unpaired exits and all regions without entrances (except the Menu)
# This function is destructive on these lists.
exits = [exit.name for r in multiworld.regions if r.player == player for exit in r.exits if exit.connected_region == None]
exits = [exit.name for r in multiworld.regions if r.player == player for exit in r.exits if exit.connected_region is None]
structs = [r.name for r in multiworld.regions if r.player == player and r.entrances == [] and r.name != 'Menu']
exits_spoiler = exits[:] # copy the original order for the spoiler log
@@ -26,19 +28,19 @@ def shuffle_structures(mc_world: World) -> None:
raise Exception(f"Invalid connection: {exit} => {struct} for player {player} ({multiworld.player_name[player]})")
# Connect plando structures first
if multiworld.plando_connections[player]:
for conn in multiworld.plando_connections[player]:
if self.options.plando_connections:
for conn in self.plando_connections:
set_pair(conn.entrance, conn.exit)
# The algorithm tries to place the most restrictive structures first. This algorithm always works on the
# relatively small set of restrictions here, but does not work on all possible inputs with valid configurations.
if multiworld.shuffle_structures[player]:
if self.options.shuffle_structures:
structs.sort(reverse=True, key=lambda s: len(illegal_connections.get(s, [])))
for struct in structs[:]:
try:
exit = multiworld.random.choice([e for e in exits if e not in illegal_connections.get(struct, [])])
exit = self.random.choice([e for e in exits if e not in illegal_connections.get(struct, [])])
except IndexError:
raise Exception(f"No valid structure placements remaining for player {player} ({multiworld.player_name[player]})")
raise Exception(f"No valid structure placements remaining for player {player} ({self.player_name})")
set_pair(exit, struct)
else: # write remaining default connections
for (exit, struct) in default_connections:
@@ -49,9 +51,9 @@ def shuffle_structures(mc_world: World) -> None:
try:
assert len(exits) == len(structs) == 0
except AssertionError:
raise Exception(f"Failed to connect all Minecraft structures for player {player} ({multiworld.player_name[player]})")
raise Exception(f"Failed to connect all Minecraft structures for player {player} ({self.player_name})")
for exit in exits_spoiler:
multiworld.get_entrance(exit, player).connect(multiworld.get_region(pairs[exit], player))
if multiworld.shuffle_structures[player] or multiworld.plando_connections[player]:
if self.options.shuffle_structures or self.options.plando_connections:
multiworld.spoiler.set_entrance(exit, pairs[exit], 'entrance', player)