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

Auto Crafters now work on Barrels, Trapped Chests and Shulker boxes

This commit is contained in:
TheBusyBiscuit 2021-03-24 23:16:07 +01:00
parent 26c7dddbf4
commit 2535295455
2 changed files with 19 additions and 10 deletions

View File

@ -847,8 +847,8 @@ public final class SlimefunItems {
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 VANILLA_AUTO_CRAFTER = new SlimefunItemStack("VANILLA_AUTO_CRAFTER", HeadTexture.VANILLA_AUTO_CRAFTER, "&2Auto-Crafter &8(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.ENHANCED_AUTO_CRAFTER, "&2Auto-Crafter &8(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 VANILLA_AUTO_CRAFTER = new SlimefunItemStack("VANILLA_AUTO_CRAFTER", HeadTexture.VANILLA_AUTO_CRAFTER, "&2Auto-Crafter &8(Vanilla)", "", "&fPlace this machine on top of a", "&fchest or similar and make it craft", "&fanything that 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.ENHANCED_AUTO_CRAFTER, "&2Auto-Crafter &8(Enhanced)", "", "&fPlace this machine on top of a", "&fchest or similar and make it craft", "&fanything that 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 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");

View File

@ -18,7 +18,6 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Skull;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@ -36,6 +35,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.AutoCrafterListener;
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import io.papermc.lib.PaperLib;
import io.papermc.lib.features.blockstatesnapshot.BlockStateSnapshotResult;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
@ -120,7 +120,7 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
Validate.notNull(p, "The Player cannot be null!");
// Check if we have a valid chest below
if (!isValidChest(b.getRelative(BlockFace.DOWN))) {
if (!isValidInventory(b.getRelative(BlockFace.DOWN))) {
SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.missing-chest");
} else if (SlimefunPlugin.getProtectionManager().hasPermission(p, b, ProtectableAction.INTERACT_BLOCK)) {
if (p.isSneaking()) {
@ -153,7 +153,7 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
Block chest = b.getRelative(BlockFace.DOWN);
// Make sure this is a Chest
if (isValidChest(chest)) {
if (isValidInventory(chest)) {
BlockState state = PaperLib.getBlockState(chest, false).getState();
if (state instanceof InventoryHolder) {
@ -170,18 +170,27 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
}
/**
* This method checks if the given {@link Block} is a valid {@link Chest}
* This method checks if the given {@link Block} has a valid {@link Inventory}
* where the Auto Crafter could be placed upon.
* Right now this only supports {@code Material.CHEST} but it can change or
* Right now this only supports chests and a few select tile entities but it can change or
* be overridden in the future.
*
* @param block
* The {@link Block} to check
*
* @return Whether that {@link Block} is a valid {@link Chest}
* @return Whether that {@link Block} has a valid {@link Inventory}
*/
protected boolean isValidChest(@Nonnull Block block) {
return block.getType() == Material.CHEST;
protected boolean isValidInventory(@Nonnull Block block) {
Material type = block.getType();
switch (type) {
case CHEST:
case TRAPPED_CHEST:
case BARREL:
return true;
default:
return SlimefunTag.SHULKER_BOXES.isTagged(type);
}
}
/**