Class LootTable

java.lang.Object
com.ryandw11.structure.loottables.LootTable
Direct Known Subclasses:
ConfigLootTable, MinecraftLootTable

public abstract class LootTable extends Object
Represents a LootTable.

You can extend this class to implement custom LootTables.

This class comes with a RandomCollection of LootItem by default. You can opt to not use this collection with your implementation by overriding getRandomWeightedItem() and getItems().

  • Field Details

    • randomCollection

      protected RandomCollection<LootItem> randomCollection
      The default RandomCollection provided.
    • types

      protected List<LootTableType> types
      The list of LootTable types.

      Avoid changing the default behavior of LootTableTypes.

  • Constructor Details

    • LootTable

      public LootTable()
      The default constructor for the LootTable which initializes the RandomCollection and list of LootTableTypes.
  • Method Details

    • getName

      public abstract String getName()
      Get the name of the LootTable.
      Returns:
      The name of the LootTable.
    • getRolls

      public abstract int getRolls()
      Get the number of rolls for the loot table. (The number of items to be chosen).
      Returns:
      The number of rolls for the loot table.
    • setRolls

      public abstract void setRolls(int rolls)
      Set the number of rolls for the loot table.

      An implementation of this method is not strictly necessary.

      Parameters:
      rolls - The number of rolls for the loot tables.
    • fillContainerInventory

      public void fillContainerInventory(org.bukkit.inventory.Inventory inventory, Random random, org.bukkit.Location location)
      Fills a container's inventory with items.

      Override this method to replace the default functionality.

      Parameters:
      inventory - The inventory to fill.
      random - The randomizer.
      location - The location of the container.
    • fillFurnaceInventory

      public void fillFurnaceInventory(org.bukkit.inventory.FurnaceInventory furnaceInventory, Random random, org.bukkit.Location location)
      Fills a furnace inventory with items.

      Override this method to replace the default functionality.

      Parameters:
      furnaceInventory - The furnace inventory to fill.
      random - The randomizer.
      location - The location of the furnace.
    • fillBrewerInventory

      public void fillBrewerInventory(org.bukkit.inventory.BrewerInventory brewerInventory, Random random, org.bukkit.Location location)
      Fills a brewer with items.

      Override this method to replace the default functionality.

      Parameters:
      brewerInventory - The brewer invetory to fill.
      random - The randomizer.
      location - The location of the furnace.
    • getRandomWeightedItem

      public org.bukkit.inventory.ItemStack getRandomWeightedItem()
      Get a random item from the loot table.

      Override this method if you don't use the default RandomCollection.

      Returns:
      A random item from the loot table.
    • getItems

      public List<LootItem> getItems()
      Get the list of items from the loot table.

      Override this method if you don't use the default RandomCollection.

      Returns:
      This list of possible items in the LootTable.
    • addLootItem

      protected final void addLootItem(double weight, @NotNull @NotNull LootItem lootItem)
      Add an item to the LootTable's random collection.
      Parameters:
      weight - The weight of the item to add.
      lootItem - The LootItem to add.
    • getTypes

      public final List<LootTableType> getTypes()
      Get the list of LootTable types.
      Returns:
      The list of LootTable types.
    • setTypes

      public final void setTypes(List<LootTableType> types)
      Set the list of LootTable types.
      Parameters:
      types - The list of types to be set.
    • addType

      public final void addType(LootTableType type)
      Add a LootTable type.
      Parameters:
      type - The LootTable type to be added.