From 0696991ab0be463a23c5a5c610d19bc7be20b3f2 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Tue, 9 Mar 2021 16:55:28 +0100 Subject: [PATCH] [CI skip] A lot of refactoring --- .../api/events/AutoDisenchantEvent.java | 2 +- .../machines/AbstractGrowthAccelerator.java | 79 ++-------- .../electric/machines/AutoDisenchanter.java | 126 +--------------- .../electric/machines/AutoEnchanter.java | 96 ++---------- .../AbstractGrowthAccelerator.java | 85 +++++++++++ .../AnimalGrowthAccelerator.java | 2 +- .../CropGrowthAccelerator.java | 2 +- .../TreeGrowthAccelerator.java | 2 +- .../machines/accelerators/package-info.java | 5 + .../machines/enchanting/AutoDisenchanter.java | 140 ++++++++++++++++++ .../machines/enchanting/AutoEnchanter.java | 102 +++++++++++++ .../machines/{ => enchanting}/BookBinder.java | 2 +- .../machines/enchanting/package-info.java | 7 + .../AbstractEntityAssembler.java | 2 +- .../ExpCollector.java} | 8 +- .../{ => entities}/IronGolemAssembler.java | 2 +- .../{ => entities}/WitherAssembler.java | 2 +- .../machines/entities/package-info.java | 6 + .../items/misc/OrganicFertilizer.java | 4 +- .../items/misc/OrganicFood.java | 2 +- .../setup/SlimefunItemSetup.java | 20 +-- .../slimefun4/utils/tags/SlimefunTag.java | 2 +- .../Slimefun/Lists/RecipeType.java | 22 ++- .../Objects/SlimefunItem/SlimefunItem.java | 28 ++-- 24 files changed, 436 insertions(+), 312 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => accelerators}/AnimalGrowthAccelerator.java (98%) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => accelerators}/CropGrowthAccelerator.java (98%) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => accelerators}/TreeGrowthAccelerator.java (98%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/package-info.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => enchanting}/BookBinder.java (99%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/package-info.java rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => entities}/AbstractEntityAssembler.java (99%) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{XPCollector.java => entities/ExpCollector.java} (94%) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => entities}/IronGolemAssembler.java (98%) rename src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/{ => entities}/WitherAssembler.java (98%) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/package-info.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java index 6bba59cae..ad33db977 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AutoDisenchantEvent.java @@ -7,7 +7,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoDisenchanter; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter; /** * An {@link Event} that is called whenever an {@link AutoDisenchanter} has diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractGrowthAccelerator.java index 065f57e1c..dbc7c49ee 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractGrowthAccelerator.java @@ -2,84 +2,25 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machine import javax.annotation.ParametersAreNonnullByDefault; -import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; -import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType; -import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; -import me.mrCookieSlime.Slimefun.api.BlockStorage; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; -public abstract class AbstractGrowthAccelerator extends SlimefunItem implements InventoryBlock, EnergyNetComponent { - - private static final int[] BORDER = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; +/** + * This has been moved. + * + * @deprecated Moved to + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.AbstractGrowthAccelerator} + * + */ +@Deprecated +public abstract class AbstractGrowthAccelerator extends io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.AbstractGrowthAccelerator { @ParametersAreNonnullByDefault public AbstractGrowthAccelerator(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); - - createPreset(this, this::constructMenu); - - registerBlockHandler(getId(), (p, b, tool, reason) -> { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - } - - return true; - }); } - private void constructMenu(BlockMenuPreset preset) { - for (int i : BORDER) { - preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler()); - } - } - - @Override - public EnergyNetComponentType getEnergyComponentType() { - return EnergyNetComponentType.CONSUMER; - } - - @Override - public int[] getInputSlots() { - return new int[] { 10, 11, 12, 13, 14, 15, 16 }; - } - - @Override - public int[] getOutputSlots() { - return new int[0]; - } - - @Override - public void preRegister() { - super.preRegister(); - addItemHandler(new BlockTicker() { - - @Override - public void tick(Block b, SlimefunItem sf, Config data) { - AbstractGrowthAccelerator.this.tick(b); - } - - @Override - public boolean isSynchronized() { - return true; - } - }); - } - - protected abstract void tick(Block b); - -} +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java index 45ca141b7..ec01e2299 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoDisenchanter.java @@ -1,140 +1,26 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.Repairable; -import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; -import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; /** - * The {@link AutoDisenchanter}, in contrast to the {@link AutoEnchanter}, removes - * {@link Enchantment Enchantments} from a given {@link ItemStack} and transfers them - * to a book. + * This has been moved. * - * @author TheBusyBiscuit - * @author Walshy - * @author poma123 - * - * @see AutoEnchanter + * @deprecated Moved to + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter} * */ -public class AutoDisenchanter extends AContainer { +@Deprecated +public class AutoDisenchanter extends io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter { @ParametersAreNonnullByDefault public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); } - @Override - public ItemStack getProgressBar() { - return new ItemStack(Material.DIAMOND_CHESTPLATE); - } - - @Override - protected MachineRecipe findNextRecipe(BlockMenu menu) { - Map enchantments = new HashMap<>(); - - for (int slot : getInputSlots()) { - ItemStack item = menu.getItemInSlot(slot); - - if (!isDisenchantable(item)) { - return null; - } - - AutoDisenchantEvent event = new AutoDisenchantEvent(item); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) { - return null; - } - - ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); - - // Disenchanting - if (target != null && target.getType() == Material.BOOK) { - int amount = 0; - - for (Map.Entry entry : item.getEnchantments().entrySet()) { - enchantments.put(entry.getKey(), entry.getValue()); - amount++; - } - - if (amount > 0) { - ItemStack disenchantedItem = item.clone(); - disenchantedItem.setAmount(1); - - ItemStack book = new ItemStack(Material.ENCHANTED_BOOK); - transferEnchantments(disenchantedItem, book, enchantments); - - MachineRecipe recipe = new MachineRecipe(90 * amount / this.getSpeed(), new ItemStack[] { target, item }, new ItemStack[] { disenchantedItem, book }); - - if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) { - return null; - } - - for (int inputSlot : getInputSlots()) { - menu.consumeItem(inputSlot); - } - - return recipe; - } - } - } - - return null; - } - - private void transferEnchantments(ItemStack item, ItemStack book, Map enchantments) { - ItemMeta itemMeta = item.getItemMeta(); - ItemMeta bookMeta = book.getItemMeta(); - ((Repairable) bookMeta).setRepairCost(((Repairable) itemMeta).getRepairCost()); - ((Repairable) itemMeta).setRepairCost(0); - item.setItemMeta(itemMeta); - book.setItemMeta(bookMeta); - - EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta(); - - for (Map.Entry entry : enchantments.entrySet()) { - item.removeEnchantment(entry.getKey()); - meta.addStoredEnchant(entry.getKey(), entry.getValue(), true); - } - - book.setItemMeta(meta); - } - - private boolean isDisenchantable(@Nullable ItemStack item) { - if (item == null) { - return false; - } else if (item.getType() != Material.BOOK) { - // ^ This stops endless checks of getByItem for books - SlimefunItem sfItem = SlimefunItem.getByItem(item); - return sfItem == null || sfItem.isDisenchantable(); - } else { - return true; - } - } - - @Override - public String getMachineIdentifier() { - return "AUTO_DISENCHANTER"; - } - -} +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java index e1550792e..d55af6b1b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AutoEnchanter.java @@ -1,102 +1,26 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; -import java.util.HashMap; -import java.util.Map; - import javax.annotation.ParametersAreNonnullByDefault; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; -import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; -public class AutoEnchanter extends AContainer { +/** + * This has been moved. + * + * @deprecated Moved to + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter} + * + */ +@Deprecated +public class AutoEnchanter extends io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter { @ParametersAreNonnullByDefault public AutoEnchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); } - @Override - public ItemStack getProgressBar() { - return new ItemStack(Material.GOLDEN_CHESTPLATE); - } - - @Override - protected MachineRecipe findNextRecipe(BlockMenu menu) { - for (int slot : getInputSlots()) { - ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); - - // Check if the item is enchantable - if (!isEnchantable(target)) { - return null; - } - - ItemStack item = menu.getItemInSlot(slot); - - if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) { - Map enchantments = new HashMap<>(); - int amount = 0; - EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); - - for (Map.Entry e : meta.getStoredEnchants().entrySet()) { - if (e.getKey().canEnchantItem(target)) { - amount++; - enchantments.put(e.getKey(), e.getValue()); - } - } - - if (amount > 0) { - ItemStack enchantedItem = target.clone(); - enchantedItem.setAmount(1); - - for (Map.Entry entry : enchantments.entrySet()) { - enchantedItem.addUnsafeEnchantment(entry.getKey(), entry.getValue()); - } - - MachineRecipe recipe = new MachineRecipe(75 * amount / this.getSpeed(), new ItemStack[] { target, item }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) }); - - if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) { - return null; - } - - for (int inputSlot : getInputSlots()) { - menu.consumeItem(inputSlot); - } - - return recipe; - } - - return null; - } - } - - return null; - } - - private boolean isEnchantable(ItemStack item) { - SlimefunItem sfItem = null; - - // stops endless checks of getByItem for enchanted book stacks. - if (item != null && item.getType() != Material.ENCHANTED_BOOK) { - sfItem = SlimefunItem.getByItem(item); - } - - return sfItem == null || sfItem.isEnchantable(); - } - - @Override - public String getMachineIdentifier() { - return "AUTO_ENCHANTER"; - } - -} +} \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java new file mode 100644 index 000000000..e7e57a2ea --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java @@ -0,0 +1,85 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; +import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent; +import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType; +import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock; +import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; + +public abstract class AbstractGrowthAccelerator extends SlimefunItem implements InventoryBlock, EnergyNetComponent { + + private static final int[] BORDER = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; + + @ParametersAreNonnullByDefault + public AbstractGrowthAccelerator(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + + createPreset(this, this::constructMenu); + + registerBlockHandler(getId(), (p, b, tool, reason) -> { + BlockMenu inv = BlockStorage.getInventory(b); + + if (inv != null) { + inv.dropItems(b.getLocation(), getInputSlots()); + } + + return true; + }); + } + + private void constructMenu(BlockMenuPreset preset) { + for (int i : BORDER) { + preset.addItem(i, new CustomItem(Material.CYAN_STAINED_GLASS_PANE, " "), ChestMenuUtils.getEmptyClickHandler()); + } + } + + @Override + public EnergyNetComponentType getEnergyComponentType() { + return EnergyNetComponentType.CONSUMER; + } + + @Override + public int[] getInputSlots() { + return new int[] { 10, 11, 12, 13, 14, 15, 16 }; + } + + @Override + public int[] getOutputSlots() { + return new int[0]; + } + + @Override + public void preRegister() { + super.preRegister(); + addItemHandler(new BlockTicker() { + + @Override + public void tick(Block b, SlimefunItem sf, Config data) { + AbstractGrowthAccelerator.this.tick(b); + } + + @Override + public boolean isSynchronized() { + return true; + } + }); + } + + protected abstract void tick(Block b); + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java index c8e774573..1629bc8bf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AnimalGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AnimalGrowthAccelerator.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators; import org.bukkit.Particle; import org.bukkit.block.Block; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java index f132a751b..893f3d070 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CropGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/CropGrowthAccelerator.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators; import org.bukkit.Particle; import org.bukkit.block.Block; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java index 5e3b21ba2..b3ef10fb6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/TreeGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/TreeGrowthAccelerator.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators; import org.bukkit.Particle; import org.bukkit.Tag; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/package-info.java new file mode 100644 index 000000000..96accec69 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains any electric machines related to growth accelerations. + * These growth accelerators speed up the growth of animals or plants. + */ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java new file mode 100644 index 000000000..7af3f137f --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoDisenchanter.java @@ -0,0 +1,140 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.Repairable; + +import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; +import io.github.thebusybiscuit.slimefun4.api.events.AutoDisenchantEvent; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; + +/** + * The {@link AutoDisenchanter}, in contrast to the {@link AutoEnchanter}, removes + * {@link Enchantment Enchantments} from a given {@link ItemStack} and transfers them + * to a book. + * + * @author TheBusyBiscuit + * @author Walshy + * @author poma123 + * + * @see AutoEnchanter + * + */ +public class AutoDisenchanter extends AContainer { + + @ParametersAreNonnullByDefault + public AutoDisenchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + } + + @Override + public ItemStack getProgressBar() { + return new ItemStack(Material.DIAMOND_CHESTPLATE); + } + + @Override + protected MachineRecipe findNextRecipe(BlockMenu menu) { + Map enchantments = new HashMap<>(); + + for (int slot : getInputSlots()) { + ItemStack item = menu.getItemInSlot(slot); + + if (!isDisenchantable(item)) { + return null; + } + + AutoDisenchantEvent event = new AutoDisenchantEvent(item); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return null; + } + + ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); + + // Disenchanting + if (target != null && target.getType() == Material.BOOK) { + int amount = 0; + + for (Map.Entry entry : item.getEnchantments().entrySet()) { + enchantments.put(entry.getKey(), entry.getValue()); + amount++; + } + + if (amount > 0) { + ItemStack disenchantedItem = item.clone(); + disenchantedItem.setAmount(1); + + ItemStack book = new ItemStack(Material.ENCHANTED_BOOK); + transferEnchantments(disenchantedItem, book, enchantments); + + MachineRecipe recipe = new MachineRecipe(90 * amount / this.getSpeed(), new ItemStack[] { target, item }, new ItemStack[] { disenchantedItem, book }); + + if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) { + return null; + } + + for (int inputSlot : getInputSlots()) { + menu.consumeItem(inputSlot); + } + + return recipe; + } + } + } + + return null; + } + + private void transferEnchantments(ItemStack item, ItemStack book, Map enchantments) { + ItemMeta itemMeta = item.getItemMeta(); + ItemMeta bookMeta = book.getItemMeta(); + ((Repairable) bookMeta).setRepairCost(((Repairable) itemMeta).getRepairCost()); + ((Repairable) itemMeta).setRepairCost(0); + item.setItemMeta(itemMeta); + book.setItemMeta(bookMeta); + + EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta(); + + for (Map.Entry entry : enchantments.entrySet()) { + item.removeEnchantment(entry.getKey()); + meta.addStoredEnchant(entry.getKey(), entry.getValue(), true); + } + + book.setItemMeta(meta); + } + + private boolean isDisenchantable(@Nullable ItemStack item) { + if (item == null) { + return false; + } else if (item.getType() != Material.BOOK) { + // ^ This stops endless checks of getByItem for books + SlimefunItem sfItem = SlimefunItem.getByItem(item); + return sfItem == null || sfItem.isDisenchantable(); + } else { + return true; + } + } + + @Override + public String getMachineIdentifier() { + return "AUTO_DISENCHANTER"; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java new file mode 100644 index 000000000..637f6ddf7 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/AutoEnchanter.java @@ -0,0 +1,102 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; + +import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; + +public class AutoEnchanter extends AContainer { + + @ParametersAreNonnullByDefault + public AutoEnchanter(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe); + } + + @Override + public ItemStack getProgressBar() { + return new ItemStack(Material.GOLDEN_CHESTPLATE); + } + + @Override + protected MachineRecipe findNextRecipe(BlockMenu menu) { + for (int slot : getInputSlots()) { + ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]); + + // Check if the item is enchantable + if (!isEnchantable(target)) { + return null; + } + + ItemStack item = menu.getItemInSlot(slot); + + if (item != null && item.getType() == Material.ENCHANTED_BOOK && target != null) { + Map enchantments = new HashMap<>(); + int amount = 0; + EnchantmentStorageMeta meta = (EnchantmentStorageMeta) item.getItemMeta(); + + for (Map.Entry e : meta.getStoredEnchants().entrySet()) { + if (e.getKey().canEnchantItem(target)) { + amount++; + enchantments.put(e.getKey(), e.getValue()); + } + } + + if (amount > 0) { + ItemStack enchantedItem = target.clone(); + enchantedItem.setAmount(1); + + for (Map.Entry entry : enchantments.entrySet()) { + enchantedItem.addUnsafeEnchantment(entry.getKey(), entry.getValue()); + } + + MachineRecipe recipe = new MachineRecipe(75 * amount / this.getSpeed(), new ItemStack[] { target, item }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) }); + + if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) { + return null; + } + + for (int inputSlot : getInputSlots()) { + menu.consumeItem(inputSlot); + } + + return recipe; + } + + return null; + } + } + + return null; + } + + private boolean isEnchantable(ItemStack item) { + SlimefunItem sfItem = null; + + // stops endless checks of getByItem for enchanted book stacks. + if (item != null && item.getType() != Material.ENCHANTED_BOOK) { + sfItem = SlimefunItem.getByItem(item); + } + + return sfItem == null || sfItem.isEnchantable(); + } + + @Override + public String getMachineIdentifier() { + return "AUTO_ENCHANTER"; + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/BookBinder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/BookBinder.java similarity index 99% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/BookBinder.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/BookBinder.java index c7fb9eb54..8f7f7b4c7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/BookBinder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/BookBinder.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/package-info.java new file mode 100644 index 000000000..b4e98ffd6 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/enchanting/package-info.java @@ -0,0 +1,7 @@ +/** + * This package contains any electric machines related to enchanting. + * Prominent examples are the + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoEnchanter} and + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting.AutoDisenchanter} + */ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.enchanting; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AbstractEntityAssembler.java similarity index 99% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AbstractEntityAssembler.java index 8c9959b58..1f887237f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/AbstractEntityAssembler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AbstractEntityAssembler.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities; import org.bukkit.Effect; import org.bukkit.Location; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java similarity index 94% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java index ea96f836a..d9aeb5f5d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/XPCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities; import java.util.Iterator; @@ -25,14 +25,14 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; -public class XPCollector extends SlimefunItem implements InventoryBlock, EnergyNetComponent { +public class ExpCollector extends SlimefunItem implements InventoryBlock, EnergyNetComponent { private final int[] border = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; private static final int ENERGY_CONSUMPTION = 10; private static final String DATA_KEY = "stored-exp"; - public XPCollector(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + public ExpCollector(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { super(category, item, recipeType, recipe); createPreset(this, this::constructMenu); @@ -91,7 +91,7 @@ public class XPCollector extends SlimefunItem implements InventoryBlock, EnergyN @Override public void tick(Block b, SlimefunItem sf, Config data) { - XPCollector.this.tick(b); + ExpCollector.this.tick(b); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/IronGolemAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/IronGolemAssembler.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/IronGolemAssembler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/IronGolemAssembler.java index 71426fc7d..398b23f8b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/IronGolemAssembler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/IronGolemAssembler.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/WitherAssembler.java similarity index 98% rename from src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java rename to src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/WitherAssembler.java index 07b4c34e2..51801cd37 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/WitherAssembler.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/WitherAssembler.java @@ -1,4 +1,4 @@ -package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines; +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/package-info.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/package-info.java new file mode 100644 index 000000000..d7723caf7 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/package-info.java @@ -0,0 +1,6 @@ +/** + * This package contains any electric machines related to {@link org.bukkit.entity.Entity} interactions, most notably + * the + * {@link io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.AbstractEntityAssembler}. + */ +package io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities; \ No newline at end of file diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFertilizer.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFertilizer.java index ff29a0426..539583f19 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFertilizer.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFertilizer.java @@ -4,9 +4,9 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.inventory.ItemStack; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.CropGrowthAccelerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.FoodComposter; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.TreeGrowthAccelerator; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.CropGrowthAccelerator; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.TreeGrowthAccelerator; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFood.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFood.java index 9b4edbbb1..0b86ee8c3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFood.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/misc/OrganicFood.java @@ -6,8 +6,8 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AnimalGrowthAccelerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.FoodFabricator; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.AnimalGrowthAccelerator; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; 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 c04289f60..a3be57874 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 @@ -78,18 +78,13 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generato import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generators.LavaGenerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generators.MagnesiumGenerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.generators.SolarGenerator; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AnimalGrowthAccelerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoAnvil; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBreeder; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoBrewer; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoDisenchanter; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoDrier; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoEnchanter; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutomatedCraftingChamber; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.BookBinder; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.CarbonPress; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ChargingBench; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.CropGrowthAccelerator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ElectricDustWasher; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ElectricFurnace; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.ElectricGoldPan; @@ -104,11 +99,16 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.FoodFabricator; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.Freezer; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.HeatedPressureChamber; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.IronGolemAssembler; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.Refinery; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.TreeGrowthAccelerator; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.WitherAssembler; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.XPCollector; +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.TreeGrowthAccelerator; +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.BookBinder; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.IronGolemAssembler; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.WitherAssembler; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.entities.ExpCollector; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NetherStarReactor; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.NuclearReactor; import io.github.thebusybiscuit.slimefun4.implementation.items.elevator.ElevatorPlate; @@ -2291,7 +2291,7 @@ public final class SlimefunItemSetup { new ItemStack[] {null, SlimefunItems.CARBONADO, null, SlimefunItems.ELECTRIC_MOTOR, new ItemStack(Material.DIAMOND_AXE), SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.MAGNESIUM_SALT, SlimefunItems.BIG_CAPACITOR, SlimefunItems.MAGNESIUM_SALT}) .register(plugin); - new XPCollector(categories.electricity, SlimefunItems.EXP_COLLECTOR, RecipeType.ENHANCED_CRAFTING_TABLE, + new ExpCollector(categories.electricity, SlimefunItems.EXP_COLLECTOR, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {null, SlimefunItems.BLISTERING_INGOT_3, null, SlimefunItems.WITHER_PROOF_OBSIDIAN, SlimefunItems.AUTO_ENCHANTER, SlimefunItems.WITHER_PROOF_OBSIDIAN, SlimefunItems.ALUMINUM_BRONZE_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.ALUMINUM_BRONZE_INGOT}) .register(plugin); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java index 14cf74b07..c8bbd4b86 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/tags/SlimefunTag.java @@ -21,7 +21,7 @@ import org.bukkit.block.data.Waterlogged; import io.github.thebusybiscuit.slimefun4.api.exceptions.TagMisconfigurationException; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.BlockPlacer; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.CropGrowthAccelerator; +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.accelerators.CropGrowthAccelerator; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.Talisman; import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.miner.IndustrialMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.tools.ClimbingPick; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Lists/RecipeType.java b/src/main/java/me/mrCookieSlime/Slimefun/Lists/RecipeType.java index 084a6bbe8..635643bb3 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Lists/RecipeType.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Lists/RecipeType.java @@ -9,6 +9,8 @@ import java.util.Locale; import java.util.Set; import java.util.function.BiConsumer; +import javax.annotation.ParametersAreNonnullByDefault; + import org.bukkit.ChatColor; import org.bukkit.Keyed; import org.bukkit.Material; @@ -138,16 +140,32 @@ public class RecipeType implements Keyed { } @Override - public NamespacedKey getKey() { + public final NamespacedKey getKey() { return key; } + @Override + public final boolean equals(Object obj) { + if (obj instanceof RecipeType) { + return ((RecipeType) obj).getKey().equals(this.getKey()); + } else { + return false; + } + } + + @Override + public final int hashCode() { + return getKey().hashCode(); + } + + @ParametersAreNonnullByDefault private static void registerBarterDrop(ItemStack[] recipe, ItemStack output) { if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) { SlimefunPlugin.getRegistry().getBarteringDrops().add(output); } } + @ParametersAreNonnullByDefault private static void registerMobDrop(ItemStack[] recipe, ItemStack output) { String mob = ChatColor.stripColor(recipe[4].getItemMeta().getDisplayName()).toUpperCase(Locale.ROOT).replace(' ', '_'); EntityType entity = EntityType.valueOf(mob); @@ -211,4 +229,4 @@ public class RecipeType implements Keyed { List recipes = machine.getRecipes(); return recipes.get((recipes.indexOf(input) + 1))[0]; } -} +} \ No newline at end of file diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java index d6e47846f..02c46fa50 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/SlimefunItem.java @@ -45,13 +45,12 @@ import io.github.thebusybiscuit.slimefun4.core.researching.Research; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoDisenchanter; -import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutoEnchanter; +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.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; -import me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler; import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker; import me.mrCookieSlime.Slimefun.Objects.handlers.ItemHandler; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; @@ -246,6 +245,13 @@ public class SlimefunItem implements Placeable { return recipe; } + /** + * This method returns the {@link RecipeType}. + * The {@link RecipeType} determines how this {@link SlimefunItem} is crafted. + * + * @return The {@link RecipeType} of this {@link SlimefunItem} + */ + @Nonnull public RecipeType getRecipeType() { return recipeType; } @@ -1159,12 +1165,16 @@ public class SlimefunItem implements Placeable { // This wrapper improves the heavy ItemStack#getItemMeta() call by caching it. ItemStackWrapper wrapper = new ItemStackWrapper(item); - // Quite expensive performance-wise - // But necessary for supporting legacy items + /* + * Quite expensive performance-wise. + * But necessary for supporting legacy items + */ for (SlimefunItem sfi : SlimefunPlugin.getRegistry().getAllSlimefunItems()) { if (sfi.isItem(wrapper)) { - // If we have to loop all items for the given item, then at least - // set the id via PersistentDataAPI for future performance boosts + /* + * If we have to loop all items for the given item, then at least + * set the id via PersistentDataAPI for future performance boosts + */ SlimefunPlugin.getItemDataService().setItemData(item, sfi.getId()); return sfi; @@ -1190,8 +1200,8 @@ public class SlimefunItem implements Placeable { * The handler */ @Deprecated - public static void registerBlockHandler(String id, SlimefunBlockHandler handler) { + public static void registerBlockHandler(String id, me.mrCookieSlime.Slimefun.Objects.SlimefunBlockHandler handler) { SlimefunPlugin.getRegistry().getBlockHandlers().put(id, handler); } -} +} \ No newline at end of file