From 6eebb9c04d68f0a633433703d873929b5f4fec6e Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sun, 17 May 2020 00:40:07 +0200 Subject: [PATCH] AncientAltar now has a speed variable --- CHANGELOG.md | 1 + .../items/altar/AncientAltar.java | 37 ++++++++++++++++++- .../listeners/AncientAltarListener.java | 7 +++- .../setup/SlimefunItemSetup.java | 2 +- .../tasks/AncientAltarTask.java | 8 +++- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fea9151a1..323a23e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * Bandages, Rags and Splints will no longer be consumed if your health is full and you are not on fire * Player Profiles (researches and stuff) are now loaded completely asynchronously * The Infused Magnet can no longer be placed down +* AncientAltar speed can now be changed internally (not available for server owners yet) #### Fixes * Fixed #1824 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientAltar.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientAltar.java index 1b8f582d6..3b785c678 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientAltar.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/altar/AncientAltar.java @@ -2,15 +2,50 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.altar; import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.slimefun4.api.events.AncientAltarCraftEvent; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.AncientAltarListener; +import io.github.thebusybiscuit.slimefun4.implementation.tasks.AncientAltarTask; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * The {@link AncientAltar} is a multiblock structure. + * The altar itself stands in the center, surrounded by {@link AncientPedestal Pedestals}, it is used + * to craft various magical items. + * + * @author TheBusyBiscuit + * + * @see AncientAltarListener + * @see AncientAltarTask + * @see AncientAltarCraftEvent + * @see AncientPedestal + * + */ public class AncientAltar extends SlimefunItem { - public AncientAltar(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + private final int speed; + + public AncientAltar(Category category, int speed, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); + + if (speed < 1) { + throw new IllegalArgumentException("The speed must be at least 1."); + } + + this.speed = speed; + } + + /** + * This returns the speed of this {@link AncientAltar}. + * This number determines how much ticks happen inbetween a step in the ritual animation. + * The default is 8 ticks. + * + * @return The speed of this {@link AncientAltar} + */ + public int getSpeed() { + return speed; } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java index 70a4fcbe4..684091360 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AncientAltarListener.java @@ -64,6 +64,11 @@ public class AncientAltarListener implements Listener { this.altar = altar; } + /** + * This returns all {@link AncientAltar Altars} that are currently in use. + * + * @return A {@link Set} of every {@link AncientAltar} currently in use + */ public Set getAltarsInUse() { return altarsInUse; } @@ -170,7 +175,7 @@ public class AncientAltarListener implements Listener { ItemUtils.consumeItem(p.getInventory().getItemInMainHand(), false); } - Slimefun.runSync(new AncientAltarTask(b, result, pedestals, consumed, p), 10L); + Slimefun.runSync(new AncientAltarTask(b, altar.getSpeed(), result, pedestals, consumed, p), 10L); } else { altars.remove(b); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index fdf13bd92..b322b709a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -1580,7 +1580,7 @@ public final class SlimefunItemSetup { new CustomItem(SlimefunItems.ANCIENT_PEDESTAL, 4)) .register(plugin); - new AncientAltar(categories.magicalGadgets, SlimefunItems.ANCIENT_ALTAR, RecipeType.MAGIC_WORKBENCH, + new AncientAltar(categories.magicalGadgets, 8, SlimefunItems.ANCIENT_ALTAR, RecipeType.MAGIC_WORKBENCH, new ItemStack[] {null, new ItemStack(Material.ENCHANTING_TABLE), null, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.GOLD_8K, SlimefunItems.MAGIC_LUMP_3, new ItemStack(Material.OBSIDIAN), SlimefunItems.GOLD_8K, new ItemStack(Material.OBSIDIAN)}) .register(plugin); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java index b57f4b67c..95b1b5bc9 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/AncientAltarTask.java @@ -40,6 +40,7 @@ public class AncientAltarTask implements Runnable { private final AncientAltarListener listener = SlimefunPlugin.getAncientAltarListener(); private final Block altar; + private final int speed; private final Location dropLocation; private final ItemStack output; private final List pedestals; @@ -52,8 +53,9 @@ public class AncientAltarTask implements Runnable { private int stage; private final Player player; - public AncientAltarTask(Block altar, ItemStack output, List pedestals, List items, Player player) { + public AncientAltarTask(Block altar, int speed, ItemStack output, List pedestals, List items, Player player) { this.dropLocation = altar.getLocation().add(0.5, 1.3, 0.5); + this.speed = speed; this.altar = altar; this.output = output; this.pedestals = pedestals; @@ -88,7 +90,7 @@ public class AncientAltarTask implements Runnable { } this.stage += 1; - Slimefun.runSync(this, 8); + Slimefun.runSync(this, speed); } private boolean checkLockedItems() { @@ -148,11 +150,13 @@ public class AncientAltarTask implements Runnable { AncientAltarCraftEvent event = new AncientAltarCraftEvent(output, altar, player); Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()) { dropLocation.getWorld().playSound(dropLocation, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F); dropLocation.getWorld().playEffect(dropLocation, Effect.STEP_SOUND, Material.EMERALD_BLOCK); dropLocation.getWorld().dropItemNaturally(dropLocation.add(0, -0.5, 0), event.getItem()); } + pedestals.forEach(b -> listener.getAltarsInUse().remove(b.getLocation())); // This should re-enable altar blocks on craft completion.