Ejemplo n.º 1
0
def recipe_crafting_table(plank):
    return Recipe(
        recipe_id=3,
        inputs=[ItemStack(plank, 4)],
        outputs=[],
        needed_properties=None,
        added_properties={"has_crafting": True},
    )
Ejemplo n.º 2
0
def recipe_wooden_pickaxe(plank, stick, wooden_pickaxe):
    return Recipe(
        recipe_id=3,
        inputs=[ItemStack(plank, 3), ItemStack(stick, 2)],
        outputs=[ItemStack(wooden_pickaxe)],
        needed_properties={"has_crafting": True},
        added_properties=None,
    )
Ejemplo n.º 3
0
    def can_craft(self, recipe: Recipe) -> bool:
        """Check if the recipe can be performed

        Args:
            recipe: Recipe to be tested.

        Return:
            True if the recipe can be used, False otherwise.

        """
        return recipe.can_craft(self.inventory, self.zone)
Ejemplo n.º 4
0
from crafting.player.inventory import Inventory
from crafting.player.player import Player

WOODEN_PICKAXE = Tool(18, "wooden_pickaxe")
AIR = Tool(0, "air")
DIRT = Item(3, "dirt", required_tools=[AIR])
WOOD = Item(17, "wood", required_tools=[AIR])
STICK = Item(280, "stick")
WOOD_PLANK = Item(5, "plank")
STONE = Item(1, "stone", required_tools=[WOODEN_PICKAXE])

R_WOOD_PLANK = Recipe(
    recipe_id=5,
    inputs=[ItemStack(WOOD, 1)],
    outputs=[ItemStack(WOOD_PLANK, 4)],
    needed_properties=None,
    added_properties=None,
)

R_STICK = Recipe(
    recipe_id=8,
    inputs=[ItemStack(WOOD_PLANK, 2)],
    outputs=[ItemStack(STICK, 4)],
    needed_properties=None,
    added_properties=None,
)

R_CRAFTING_TABLE = Recipe(
    recipe_id=28,
    inputs=[ItemStack(WOOD_PLANK, 4)],
Ejemplo n.º 5
0
    def _build_recipes(
        self,
        items: List[Item],
        findables: List[Item],
        n_inputs_per_craft: List[float],
        items_per_tool: Dict[int, List[Item]],
    ) -> List[Recipe]:
        """Build random recipes to make every item accessible.

        Args:
            items: List of items.
            findables: List of findable items.
            n_inputs_per_craft: List of probabilities of having x+1 inputs where x is the index.
            items_per_tool: Dictionary mapping tool item_id to all findable items that requires it.

        Returns:
            List of random recipes.

        """
        recipes = []
        accessible_items = set(findable for findable in findables
                               if findable.required_tools is None)

        unaccessible_items = [item for item in items if item not in findables]
        self.np_random.shuffle(unaccessible_items)

        while len(accessible_items) < len(items):
            new_accessible_item = unaccessible_items.pop()
            new_is_tool = isinstance(new_accessible_item, Tool)

            # Don't build recipes from tools or unaccesible items
            accessible_notool_items = [
                item for item in items
                if item in accessible_items and not isinstance(item, Tool)
            ]

            outputs = [ItemStack(new_accessible_item)]

            # Chooses randomly the number of input items (>=1)
            n_inputs_probs = np.array(n_inputs_per_craft) / np.sum(
                n_inputs_per_craft)
            n_inputs = 1 + self.np_random.choice(range(len(n_inputs_probs)),
                                                 p=n_inputs_probs)
            n_inputs = min(n_inputs, len(accessible_notool_items))

            # Chooses randomly accessible items and build ItemStacks of size 1 (default).
            input_items = list(
                self.np_random.choice(accessible_notool_items,
                                      size=n_inputs,
                                      replace=False))
            inputs = [ItemStack(item) for item in input_items]

            # Build recipe
            new_recipe = Recipe(len(recipes), inputs=inputs, outputs=outputs)
            recipes.append(new_recipe)

            # If new accessible item is a tool,
            #   add findables that can be gathered with it in accessible items
            if new_is_tool:
                for new_accessible_item_by_tool in items_per_tool[
                        new_accessible_item.item_id]:
                    accessible_items.add(new_accessible_item_by_tool)
            accessible_items.add(new_accessible_item)

        return recipes
Ejemplo n.º 6
0
""" Minecraft Recipes

All used Minecraft recipies.

"""

from crafting.world.items import ItemStack
from crafting.world.recipes import Recipe

from crafting.examples.minecraft.items import *
from crafting.examples.minecraft.tools import *

# Hand-Crafting items
#: Recipe of WOOD_PLANK
R_WOOD_PLANK = Recipe(5,
                      inputs=[ItemStack(WOOD, 1)],
                      outputs=[ItemStack(WOOD_PLANK, 4)])
#: Recipe of STICK
R_STICK = Recipe(280,
                 inputs=[ItemStack(WOOD_PLANK, 2)],
                 outputs=[ItemStack(STICK, 4)])
R_HAND = [R_WOOD_PLANK, R_STICK]

# Zone modifiers
#: Recipe of CRAFTING_TABLE (enable 'has_crafting' zone property)
R_CRAFTING_TABLE = Recipe(
    58,
    inputs=[ItemStack(WOOD_PLANK, 4)],
    added_properties={"has_crafting": True},
)
#: Recipe of FURNACE (enable 'has_furnace' zone property)