mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Finished Auto-Crafters
This commit is contained in:
parent
2d050a8e35
commit
057fad1f08
@ -841,10 +841,15 @@ public final class SlimefunItems {
|
|||||||
public static final SlimefunItemStack ELECTRIC_INGOT_FACTORY_2 = new SlimefunItemStack("ELECTRIC_INGOT_FACTORY_2", Material.RED_TERRACOTTA, "&cElectric Ingot Factory &7(&eII&7)", "", LoreBuilder.machine(MachineTier.BASIC, MachineType.MACHINE), LoreBuilder.speed(2), LoreBuilder.powerPerSecond(14));
|
public static final SlimefunItemStack ELECTRIC_INGOT_FACTORY_2 = new SlimefunItemStack("ELECTRIC_INGOT_FACTORY_2", Material.RED_TERRACOTTA, "&cElectric Ingot Factory &7(&eII&7)", "", LoreBuilder.machine(MachineTier.BASIC, MachineType.MACHINE), LoreBuilder.speed(2), LoreBuilder.powerPerSecond(14));
|
||||||
public static final SlimefunItemStack ELECTRIC_INGOT_FACTORY_3 = new SlimefunItemStack("ELECTRIC_INGOT_FACTORY_3", Material.RED_TERRACOTTA, "&cElectric Ingot Factory &7(&eIII&7)", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), LoreBuilder.speed(8), LoreBuilder.powerPerSecond(40));
|
public static final SlimefunItemStack ELECTRIC_INGOT_FACTORY_3 = new SlimefunItemStack("ELECTRIC_INGOT_FACTORY_3", Material.RED_TERRACOTTA, "&cElectric Ingot Factory &7(&eIII&7)", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), LoreBuilder.speed(8), LoreBuilder.powerPerSecond(40));
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static final SlimefunItemStack AUTOMATED_CRAFTING_CHAMBER = new SlimefunItemStack("AUTOMATED_CRAFTING_CHAMBER", Material.CRAFTING_TABLE, "&6Automated Crafting Chamber", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &710 J/Item");
|
public static final SlimefunItemStack AUTOMATED_CRAFTING_CHAMBER = new SlimefunItemStack("AUTOMATED_CRAFTING_CHAMBER", Material.CRAFTING_TABLE, "&6Automated Crafting Chamber", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &710 J/Item");
|
||||||
|
|
||||||
public static final SlimefunItemStack FLUID_PUMP = new SlimefunItemStack("FLUID_PUMP", Material.BLUE_TERRACOTTA, "&9Fluid Pump", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &732 J/Block");
|
public static final SlimefunItemStack FLUID_PUMP = new SlimefunItemStack("FLUID_PUMP", Material.BLUE_TERRACOTTA, "&9Fluid Pump", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &732 J/Block");
|
||||||
public static final SlimefunItemStack CHARGING_BENCH = new SlimefunItemStack("CHARGING_BENCH", Material.CRAFTING_TABLE, "&6Charging Bench", "", "&fCharges Items such as Jetpacks", "", LoreBuilder.machine(MachineTier.BASIC, MachineType.MACHINE), LoreBuilder.powerBuffer(128), "&8\u21E8 &e\u26A1 &7Energy Loss: &c50%");
|
public static final SlimefunItemStack CHARGING_BENCH = new SlimefunItemStack("CHARGING_BENCH", Material.CRAFTING_TABLE, "&6Charging Bench", "", "&fCharges Items such as Jetpacks", "", LoreBuilder.machine(MachineTier.BASIC, MachineType.MACHINE), LoreBuilder.powerBuffer(128), "&8\u21E8 &e\u26A1 &7Energy Loss: &c50%");
|
||||||
|
|
||||||
|
public static final SlimefunItemStack VANILLA_AUTO_CRAFTER = new SlimefunItemStack("VANILLA_AUTO_CRAFTER", HeadTexture.PORTABLE_CRAFTER, "&aAuto-Crafter &7(Vanilla)", "", "&fPlace this machine on top of a", "&fchest and make it craft anything", "&fthat can be crafted using a", "&fnormal &eCrafting Table", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &716 J/Item");
|
||||||
|
public static final SlimefunItemStack ENHANCED_AUTO_CRAFTER = new SlimefunItemStack("ENHANCED_AUTO_CRAFTER", HeadTexture.PORTABLE_CRAFTER, "&aAuto-Crafter &7(Enhanced)", "", "&fPlace this machine on top of a", "&fchest and make it craft anything", "&fthat can be crafted using an", "&eEnhanced Crafting Table", "", LoreBuilder.machine(MachineTier.ADVANCED, MachineType.MACHINE), "&8\u21E8 &e\u26A1 &716 J/Item");
|
||||||
|
|
||||||
public static final SlimefunItemStack IRON_GOLEM_ASSEMBLER = new SlimefunItemStack("IRON_GOLEM_ASSEMBLER", Material.IRON_BLOCK, "&6Iron Golem Assembler", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Cooldown: &b30 Seconds", LoreBuilder.powerBuffer(4096), "&8\u21E8 &e\u26A1 &72048 J/Golem");
|
public static final SlimefunItemStack IRON_GOLEM_ASSEMBLER = new SlimefunItemStack("IRON_GOLEM_ASSEMBLER", Material.IRON_BLOCK, "&6Iron Golem Assembler", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Cooldown: &b30 Seconds", LoreBuilder.powerBuffer(4096), "&8\u21E8 &e\u26A1 &72048 J/Golem");
|
||||||
public static final SlimefunItemStack WITHER_ASSEMBLER = new SlimefunItemStack("WITHER_ASSEMBLER", Material.OBSIDIAN, "&5Wither Assembler", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Cooldown: &b30 Seconds", LoreBuilder.powerBuffer(4096), "&8\u21E8 &e\u26A1 &74096 J/Wither");
|
public static final SlimefunItemStack WITHER_ASSEMBLER = new SlimefunItemStack("WITHER_ASSEMBLER", Material.OBSIDIAN, "&5Wither Assembler", "", LoreBuilder.machine(MachineTier.END_GAME, MachineType.MACHINE), "&8\u21E8 &7Cooldown: &b30 Seconds", LoreBuilder.powerBuffer(4096), "&8\u21E8 &e\u26A1 &74096 J/Wither");
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import javax.annotation.Nullable;
|
|||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@ -70,7 +71,7 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
protected final NamespacedKey recipeStorageKey;
|
protected final NamespacedKey recipeStorageKey;
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
private final int[] background = {
|
protected final int[] background = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||||
9, 10, 14, 15, 16, 17,
|
9, 10, 14, 15, 16, 17,
|
||||||
18, 19, 23, 25, 26,
|
18, 19, 23, 25, 26,
|
||||||
@ -196,7 +197,7 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
ChestMenuUtils.drawBackground(menu, background);
|
ChestMenuUtils.drawBackground(menu, background);
|
||||||
ChestMenuUtils.drawBackground(menu, 45, 46, 47, 48, 50, 51, 52, 53);
|
ChestMenuUtils.drawBackground(menu, 45, 46, 47, 48, 50, 51, 52, 53);
|
||||||
|
|
||||||
menu.addItem(49, new CustomItem(Material.BARRIER, SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.remove")));
|
menu.addItem(49, new CustomItem(Material.BARRIER, ChatColor.RED + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.remove")));
|
||||||
menu.addMenuClickHandler(49, (pl, item, slot, action) -> {
|
menu.addMenuClickHandler(49, (pl, item, slot, action) -> {
|
||||||
setSelectedRecipe(b, null);
|
setSelectedRecipe(b, null);
|
||||||
pl.closeInventory();
|
pl.closeInventory();
|
||||||
|
@ -8,8 +8,12 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Skull;
|
import org.bukkit.block.Skull;
|
||||||
@ -20,10 +24,13 @@ import org.bukkit.inventory.ShapedRecipe;
|
|||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
|
||||||
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
|
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
|
||||||
|
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask;
|
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
|
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
@ -89,13 +96,57 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
|
|||||||
if (recipes.isEmpty()) {
|
if (recipes.isEmpty()) {
|
||||||
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes");
|
||||||
} else {
|
} else {
|
||||||
// TODO Choose vanilla recipe
|
ChestMenu menu = new ChestMenu(getItemName());
|
||||||
|
menu.setPlayerInventoryClickable(false);
|
||||||
|
menu.setEmptySlotsClickable(false);
|
||||||
|
|
||||||
|
ChestMenuUtils.drawBackground(menu, background);
|
||||||
|
ChestMenuUtils.drawBackground(menu, 45, 47, 48, 50, 51, 53);
|
||||||
|
// 46 // 52
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
private void offerRecipe(Player p, Block b, List<Recipe> recipes, int page, BlockMenu menu, AsyncRecipeChoiceTask task) {
|
private void offerRecipe(Player p, Block b, List<Recipe> recipes, int index, BlockMenu menu, AsyncRecipeChoiceTask task) {
|
||||||
|
Validate.isTrue(index >= 0 && index < recipes.size(), "page must be between 0 and " + (recipes.size() - 1));
|
||||||
|
|
||||||
|
menu.addItem(46, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.size()));
|
||||||
|
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
|
||||||
|
if (index > 0) {
|
||||||
|
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
|
||||||
|
offerRecipe(p, b, recipes, index - 1, menu, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
menu.addItem(52, ChestMenuUtils.getNextButton(p, index + 1, recipes.size()));
|
||||||
|
menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
|
||||||
|
if (index < (recipes.size() - 1)) {
|
||||||
|
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
|
||||||
|
offerRecipe(p, b, recipes, index + 1, menu, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
AbstractRecipe recipe = AbstractRecipe.of(recipes.get(index));
|
||||||
|
|
||||||
|
menu.addItem(49, new CustomItem(Material.CRAFTING_TABLE, ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.select")));
|
||||||
|
menu.addMenuClickHandler(49, (pl, slot, item, action) -> {
|
||||||
|
setSelectedRecipe(b, recipe);
|
||||||
|
pl.closeInventory();
|
||||||
|
|
||||||
|
p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
|
||||||
|
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-set");
|
||||||
|
showRecipe(p, b, recipe);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
task.clear();
|
||||||
|
recipe.show(menu, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -102,6 +102,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines
|
|||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.AnimalGrowthAccelerator;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.AnimalGrowthAccelerator;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.CropGrowthAccelerator;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.CropGrowthAccelerator;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.TreeGrowthAccelerator;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.TreeGrowthAccelerator;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.auto_crafters.EnhancedAutoCrafter;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.auto_crafters.VanillaAutoCrafter;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.BookBinder;
|
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.BookBinder;
|
||||||
@ -2578,7 +2580,19 @@ public final class SlimefunItemSetup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new ElytraCap(categories.magicalArmor, SlimefunItems.ELYTRA_CAP, RecipeType.ARMOR_FORGE,
|
new ElytraCap(categories.magicalArmor, SlimefunItems.ELYTRA_CAP, RecipeType.ARMOR_FORGE,
|
||||||
new ItemStack[]{new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.LEATHER_HELMET), new ItemStack(Material.SLIME_BALL)})
|
new ItemStack[] {new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.LEATHER_HELMET), new ItemStack(Material.SLIME_BALL)})
|
||||||
|
.register(plugin);
|
||||||
|
|
||||||
|
new VanillaAutoCrafter(categories.cargo, SlimefunItems.VANILLA_AUTO_CRAFTER, RecipeType.ENHANCED_CRAFTING_TABLE,
|
||||||
|
new ItemStack[] {null, SlimefunItems.BLISTERING_INGOT_3, null, new ItemStack(Material.CRAFTING_TABLE), SlimefunItems.CARGO_MOTOR, new ItemStack(Material.CRAFTING_TABLE), null, SlimefunItems.ELECTRIC_MOTOR, null})
|
||||||
|
.setCapacity(256)
|
||||||
|
.setEnergyConsumption(16)
|
||||||
|
.register(plugin);
|
||||||
|
|
||||||
|
new EnhancedAutoCrafter(categories.cargo, SlimefunItems.ENHANCED_AUTO_CRAFTER, RecipeType.ENHANCED_CRAFTING_TABLE,
|
||||||
|
new ItemStack[] {null, SlimefunItems.VANILLA_AUTO_CRAFTER, null, new ItemStack(Material.CRAFTING_TABLE), new ItemStack(Material.DISPENSER), new ItemStack(Material.CRAFTING_TABLE), null, SlimefunItems.CARGO_MOTOR, null})
|
||||||
|
.setCapacity(256)
|
||||||
|
.setEnergyConsumption(16)
|
||||||
.register(plugin);
|
.register(plugin);
|
||||||
|
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
@ -92,6 +92,20 @@ public class AsyncRecipeChoiceTask implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method clears the {@link AsyncRecipeChoiceTask} and removes all active
|
||||||
|
* iterators.
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
lock.writeLock().lock();
|
||||||
|
|
||||||
|
try {
|
||||||
|
iterators.clear();
|
||||||
|
} finally {
|
||||||
|
lock.writeLock().unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Terminate the task when noone is viewing the Inventory
|
// Terminate the task when noone is viewing the Inventory
|
||||||
|
Loading…
Reference in New Issue
Block a user