MCPcopy Create free account
hub / github.com/VolmitSoftware/Adapt / BrewingTask

Class BrewingTask

src/main/java/com/volmit/adapt/api/potion/BrewingTask.java:14–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import org.bukkit.scheduler.BukkitRunnable;
13
14public class BrewingTask extends BukkitRunnable {
15
16 private static final int DEFAULT_BREW_TIME = 400;
17
18 @Getter
19 private final BrewingRecipe recipe;
20
21 private final Location location;
22 private int brewTime;
23
24 public BrewingTask(BrewingRecipe recipe, Location loc) {
25 this.recipe = recipe;
26 this.location = loc;
27 this.brewTime = recipe.getBrewingTime();
28
29 BrewingStand block = (BrewingStand) loc.getBlock().getState();
30 if (block.getFuelLevel() > recipe.getFuelCost()) {
31 block.setFuelLevel(block.getFuelLevel() - recipe.getFuelCost());
32 } else {
33 int rest = recipe.getFuelCost() - block.getFuelLevel();
34 block.getInventory().setIngredient(decrease(block.getInventory().getFuel(), 1 + rest / 20));
35 block.setFuelLevel(20 - rest % 20);
36 }
37
38 block.setBrewingTime(DEFAULT_BREW_TIME);
39 block.update(true);
40
41 runTaskTimer(Adapt.instance, 0L, 1L);
42 }
43
44 public static ItemStack decrease(ItemStack source, int amount) {
45 if (source.getAmount() > amount) {
46 source.setAmount(source.getAmount() - amount);
47 return source;
48 } else {
49 return new ItemStack(Material.AIR);
50 }
51 }
52
53 public static boolean isValid(BrewingRecipe recipe, Location loc) {
54 BrewingStand block = (BrewingStand) loc.getBlock().getState();
55 BrewerInventory inv = block.getInventory();
56 if (inv.getIngredient() == null || recipe.getIngredient() != inv.getIngredient().getType()) {
57 return false;
58 }
59
60 int totalFuel = (inv.getFuel() != null && inv.getFuel().getType() != Material.AIR ? inv.getFuel().getAmount() * 20 : 0) + block.getFuelLevel();
61 if (totalFuel < recipe.getFuelCost()) {
62 return false;
63 }
64
65 for (int i = 0; i < 3; i++) {
66 if (recipe.getBasePotion().isSimilar(inv.getItem(i))) {
67 return true;
68 }
69 }
70
71 return false;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected