1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

AncientAltar now has a speed variable

This commit is contained in:
TheBusyBiscuit 2020-05-17 00:40:07 +02:00
parent dec22b9960
commit 6eebb9c04d
5 changed files with 50 additions and 5 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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<Location> 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);

View File

@ -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);

View File

@ -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<Block> pedestals;
@ -52,8 +53,9 @@ public class AncientAltarTask implements Runnable {
private int stage;
private final Player player;
public AncientAltarTask(Block altar, ItemStack output, List<Block> pedestals, List<ItemStack> items, Player player) {
public AncientAltarTask(Block altar, int speed, ItemStack output, List<Block> pedestals, List<ItemStack> 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.