Package io.github.apfelcreme.Pipes
Class PipesUtil
java.lang.Object
io.github.apfelcreme.Pipes.PipesUtil
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.bukkit.block.BlockFace[]
static final int[][]
static final Random
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
addFuel
(org.bukkit.inventory.Inventory source, org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack) Add fuel to an inventory that supports fuelstatic void
addItem
(org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack) Add an item to an inventory.static boolean
containsSimilar
(Collection<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack) checks if the given list of items contains an item stack similar to the given item stackstatic AbstractPipePart
convertToPipePart
(org.bukkit.block.BlockState state, PipesItem type) This is a helper method to convert a block to a PipesPart.static int
Get the amount of times that a character appears in a certain string (array)static double
getCompostableChance
(org.bukkit.Material type) Gets the chance that a compostable item has to fill a layerstatic org.bukkit.inventory.ItemStack
getFirstSimilar
(List<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack) checks if the given list of items contains an item stack similar to the given item stack and returns the first onestatic org.bukkit.inventory.ItemStack
getFuel
(org.bukkit.inventory.Inventory inventory) Get the fuel of an inventory (currently either of type BREWING or FURNACE)static PipesItem
getPipesItem
(org.bukkit.block.Block block) Get thePipesItem
from a Blockstatic PipesItem
getPipesItem
(org.bukkit.block.BlockState state) static PipesItem
getPipesItem
(org.bukkit.inventory.ItemStack item) Get thePipesItem
from an ItemStackstatic boolean
returns whether a string only contains numbersstatic boolean
isSimilarFuzzy
(org.bukkit.inventory.ItemStack a, org.bukkit.inventory.ItemStack b) Check if two ItemStacks are similar ignoring amounts and metastatic org.bukkit.inventory.ItemStack
moveToSingleSlot
(org.bukkit.inventory.Inventory source, org.bukkit.inventory.ItemStack current, org.bukkit.inventory.ItemStack added) Calculate the result itemstack that should be moved to a single slot containing some itemstatic boolean
potionAcceptsIngredient
(org.bukkit.inventory.ItemStack itemStack, org.bukkit.inventory.ItemStack ingredient) Check whether or not a certain potion item can accepts an ingredientstatic void
removeItems
(org.bukkit.inventory.Inventory inventory, org.bukkit.Material material, int count, boolean removeSpecial) Remove a specific material from an inventorystatic void
setFuel
(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack) Set the fuel of an inventory (currently either of type BREWING or FURNACE)
-
Field Details
-
RANDOM
-
BLOCK_FACES
public static final org.bukkit.block.BlockFace[] BLOCK_FACES -
OFFSETS
public static final int[][] OFFSETS
-
-
Constructor Details
-
PipesUtil
public PipesUtil()
-
-
Method Details
-
isNumeric
returns whether a string only contains numbers- Parameters:
string
- the string to be checked- Returns:
- true or false
-
getPipesItem
Get thePipesItem
from an ItemStack- Parameters:
item
- the ItemStack- Returns:
- the PipesItem or null if none found
-
getPipesItem
Get thePipesItem
from a Block- Parameters:
block
- the Block- Returns:
- the PipesItem or null if none found
-
getPipesItem
-
convertToPipePart
This is a helper method to convert a block to a PipesPart.- Parameters:
state
- The block state to converttype
- The type of the part- Returns:
- the pipe part or
null
if the block isn't one
-
removeItems
public static void removeItems(org.bukkit.inventory.Inventory inventory, org.bukkit.Material material, int count, boolean removeSpecial) Remove a specific material from an inventory- Parameters:
inventory
- the inventorymaterial
- the materialcount
- the amount to removeremoveSpecial
- should we remove items that have meta/enchantments/are damaged?
-
containsSimilar
public static boolean containsSimilar(Collection<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack) checks if the given list of items contains an item stack similar to the given item stack- Parameters:
items
- a list of item stacksitemStack
- an item stack- Returns:
- true if there is an item stack of the same type with the same data. Amount may vary
-
getFirstSimilar
public static org.bukkit.inventory.ItemStack getFirstSimilar(List<org.bukkit.inventory.ItemStack> items, org.bukkit.inventory.ItemStack itemStack) checks if the given list of items contains an item stack similar to the given item stack and returns the first one- Parameters:
items
- a list of item stacksitemStack
- an item stack- Returns:
- The first itemstack matching this one or null if none was found
-
isSimilarFuzzy
public static boolean isSimilarFuzzy(org.bukkit.inventory.ItemStack a, org.bukkit.inventory.ItemStack b) Check if two ItemStacks are similar ignoring amounts and meta- Parameters:
a
- First item stackb
- Second item stack- Returns:
- Whether or not they are similar
-
setFuel
public static void setFuel(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack) Set the fuel of an inventory (currently either of type BREWING or FURNACE)- Parameters:
inventory
- The inventory that accepts fuelitemStack
- The item that should be placed as fuel
-
getFuel
public static org.bukkit.inventory.ItemStack getFuel(org.bukkit.inventory.Inventory inventory) Get the fuel of an inventory (currently either of type BREWING or FURNACE)- Parameters:
inventory
- The inventory that accepts fuel- Returns:
- The fuel ItemStack
-
addItem
public static void addItem(org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack) Add an item to an inventory. This more complex method is necessary as not every implementation sets the leftover amount- Parameters:
target
- Where to move the item toitemStack
- The item stack
-
addFuel
public static boolean addFuel(org.bukkit.inventory.Inventory source, org.bukkit.inventory.Inventory target, org.bukkit.inventory.ItemStack itemStack) Add fuel to an inventory that supports fuel- Parameters:
source
- The inventory that we move it fromtarget
- Where to move the item toitemStack
- The item stack- Returns:
- Whether or not the fuel was successfully set
-
moveToSingleSlot
public static org.bukkit.inventory.ItemStack moveToSingleSlot(org.bukkit.inventory.Inventory source, org.bukkit.inventory.ItemStack current, org.bukkit.inventory.ItemStack added) Calculate the result itemstack that should be moved to a single slot containing some item- Parameters:
source
- The inventory the added item is coming fromcurrent
- The current item in the target inventoryadded
- The item to be added to the target- Returns:
- The item stack that should be added to the target inventory
-
potionAcceptsIngredient
public static boolean potionAcceptsIngredient(org.bukkit.inventory.ItemStack itemStack, org.bukkit.inventory.ItemStack ingredient) throws IllegalArgumentException Check whether or not a certain potion item can accepts an ingredient- Parameters:
itemStack
- The potion to checkingredient
- The ingredient- Returns:
true
if the potion can be brewed with the ingredient;false
if not- Throws:
IllegalArgumentException
- When the input item is not a potion
-
countChar
Get the amount of times that a character appears in a certain string (array)- Parameters:
c
- The characterstrings
- The string(s) to search ing- Returns:
- The amount of times the character appears in the string(s)
-
getCompostableChance
public static double getCompostableChance(org.bukkit.Material type) Gets the chance that a compostable item has to fill a layer- Parameters:
type
- The item type- Returns:
- The chance, 0 if it isn't compostable
-