java.lang.Object
io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.AbstractAutoCrafter
All Implemented Interfaces:
EnergyNetComponent, ItemAttribute, Placeable
Direct Known Subclasses:
SlimefunAutoCrafter, VanillaAutoCrafter

public abstract class AbstractAutoCrafter extends SlimefunItem implements EnergyNetComponent
This is the abstract super class for our auto crafters.
Author:
TheBusyBiscuit
See Also:
  • Field Details

    • recipeStorageKey

      protected final NamespacedKey recipeStorageKey
      The NamespacedKey used to store recipe data.
    • recipeEnabledKey

      protected final NamespacedKey recipeEnabledKey
      The NamespacedKey used to determine whether the recipe is enabled.
    • background

      protected final int[] background
  • Constructor Details

  • Method Details

    • onRightClick

      @ParametersAreNonnullByDefault public void onRightClick(Block b, Player p)
      This method handles our right-clicking behaviour.

      Do not call this method directly, see our AutoCrafterListener for the intended use case.

      Parameters:
      b - The Block that was clicked
      p - The Player who clicked
    • tick

      protected void tick(@Nonnull Block b, @Nonnull Config data)
      This method performs one tick for the AbstractAutoCrafter.
      Parameters:
      b - The block for this AbstractAutoCrafter
      data - The data stored on this block
    • isValidInventory

      protected boolean isValidInventory(@Nonnull Block block)
      This method checks if the given Block has a valid Inventory where the Auto Crafter could be placed upon. Right now this only supports chests and a few select tile entities but it can change or be overridden in the future.
      Parameters:
      block - The Block to check
      Returns:
      Whether that Block has a valid Inventory
    • getSelectedRecipe

      @Nullable public abstract AbstractRecipe getSelectedRecipe(@Nonnull Block b)
      This method returns the currently selected AbstractRecipe for the given Block.
      Parameters:
      b - The Block
      Returns:
      The currently selected AbstractRecipe or null
    • updateRecipe

      protected abstract void updateRecipe(@Nonnull Block b, @Nonnull Player p)
      This method is called when a Player right clicks the AbstractAutoCrafter while holding the shift button. Use it to choose the AbstractRecipe.
      Parameters:
      b - The Block which was clicked
      p - The Player who clicked
    • setSelectedRecipe

      protected void setSelectedRecipe(@Nonnull Block b, @Nullable AbstractRecipe recipe)
      This method sets the selected AbstractRecipe for the given Block. The recipe will be stored using the PersistentDataAPI.
      Parameters:
      b - The Block to store the data on
      recipe - The AbstractRecipe to select
    • showRecipe

      @ParametersAreNonnullByDefault protected void showRecipe(Player p, Block b, AbstractRecipe recipe)
      This shows the given AbstractRecipe to the Player in a preview window.
      Parameters:
      p - The Player
      b - The Block of the AbstractAutoCrafter
      recipe - The AbstractRecipe to show them
    • matches

      @ParametersAreNonnullByDefault protected boolean matches(ItemStack item, Predicate<ItemStack> predicate)
      This method checks whether the given Predicate matches the provided ItemStack.
      Parameters:
      item - The ItemStack to check
      predicate - The Predicate
      Returns:
      Whether the Predicate matches the ItemStack
    • matchesAny

      @ParametersAreNonnullByDefault protected boolean matchesAny(Inventory inv, Map<Integer,Integer> itemQuantities, Predicate<ItemStack> predicate)
    • craft

      public boolean craft(@Nonnull Inventory inv, @Nonnull AbstractRecipe recipe)
      This method performs a crafting operation. It will attempt to fulfill the provided AbstractRecipe using the given Inventory. This will consume items and add the result to the Inventory. This method does not handle energy consumption.
      Parameters:
      inv - The Inventory to take resources from
      recipe - The AbstractRecipe to craft
      Returns:
      Whether this crafting operation was successful or not
    • getCapacity

      public int getCapacity()
      This method returns the max amount of electricity this machine can hold.
      Specified by:
      getCapacity in interface EnergyNetComponent
      Returns:
      The max amount of electricity this Block can store.
    • getEnergyConsumption

      public int getEnergyConsumption()
      This method returns the amount of energy that is consumed per operation.
      Returns:
      The rate of energy consumption
    • setCapacity

      @Nonnull public final AbstractAutoCrafter setCapacity(int capacity)
      This sets the energy capacity for this machine. This method must be called before registering the item and only before registering.
      Parameters:
      capacity - The amount of energy this machine can store
      Returns:
      This method will return the current instance of AContainer, so that it can be chained.
    • setEnergyConsumption

      @Nonnull public final AbstractAutoCrafter setEnergyConsumption(int energyConsumption)
      This method sets the energy consumed by this machine per tick.
      Parameters:
      energyConsumption - The energy consumed per tick
      Returns:
      This method will return the current instance of AContainer, so that it can be chained.
    • register

      public void register(@Nonnull SlimefunAddon addon)
      Description copied from class: SlimefunItem
      This method registers this SlimefunItem. Always call this method after your SlimefunItem has been initialized. Never call it more than once!
      Overrides:
      register in class SlimefunItem
      Parameters:
      addon - The SlimefunAddon that this SlimefunItem belongs to.
    • getEnergyComponentType

      public final EnergyNetComponentType getEnergyComponentType()
      Description copied from interface: EnergyNetComponent
      This method returns the Type of EnergyNetComponentType this SlimefunItem represents. It describes how this Block will interact with an EnergyNet.
      Specified by:
      getEnergyComponentType in interface EnergyNetComponent
      Returns:
      The EnergyNetComponentType this SlimefunItem represents.