From e76bfc486a4475a3a1c8b85f3e5195e305df7aa1 Mon Sep 17 00:00:00 2001 From: lijinhong11 Date: Sun, 3 Nov 2024 08:14:21 +0800 Subject: [PATCH] feat: InfinityExpansion-like storages --- pom.xml | 2 +- .../me/mmmjjkx/betterChests/BCGroups.java | 12 +- .../betterChests/items/BCItemStacks.java | 19 +- .../mmmjjkx/betterChests/items/BCItems.java | 195 +++++-- .../items/chests/SimpleChest.java | 2 +- .../items/chests/SimpleDrawer.java | 20 +- .../items/chests/ie/IEStorageCache.java | 486 ++++++++++++++++++ .../items/chests/ie/IEStorageUnit.java | 295 +++++++++++ .../items/machines/ChestDisassembler.java | 20 +- .../items/tools/ChestColorer.java | 2 +- .../items/tools/LocationRecorder.java | 2 +- .../items/tools/MultiLocationRecorder.java | 30 ++ src/main/resources/plugin.yml | 2 +- 13 files changed, 1015 insertions(+), 72 deletions(-) create mode 100644 src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageCache.java create mode 100644 src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageUnit.java create mode 100644 src/main/java/me/mmmjjkx/betterChests/items/tools/MultiLocationRecorder.java diff --git a/pom.xml b/pom.xml index e896de8..3eac407 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ io.papermc.paper paper-api - 1.20.1-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT provided diff --git a/src/main/java/me/mmmjjkx/betterChests/BCGroups.java b/src/main/java/me/mmmjjkx/betterChests/BCGroups.java index 1fbbbc3..cc35b05 100644 --- a/src/main/java/me/mmmjjkx/betterChests/BCGroups.java +++ b/src/main/java/me/mmmjjkx/betterChests/BCGroups.java @@ -1,11 +1,17 @@ package me.mmmjjkx.betterChests; -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.groups.NestedItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup; import me.mmmjjkx.betterChests.items.BCItemStacks; import org.bukkit.NamespacedKey; public class BCGroups { private static final NamespacedKey MAIN_KEY = new NamespacedKey(BetterChests.INSTANCE, "group_main"); - - public static final ItemGroup MAIN = new ItemGroup(MAIN_KEY, BCItemStacks.GROUP_MAIN_ITEM); + public static final NestedItemGroup MAIN = new NestedItemGroup(MAIN_KEY, BCItemStacks.GROUP_MAIN_ITEM, 2); + private static final NamespacedKey STORAGES_KEY = new NamespacedKey(BetterChests.INSTANCE, "group_storages"); + public static final SubItemGroup STORAGES = new SubItemGroup(STORAGES_KEY, MAIN, BCItemStacks.GROUP_STORAGE_ITEM); + private static final NamespacedKey TOOLS_KEY = new NamespacedKey(BetterChests.INSTANCE, "group_tools"); + public static final SubItemGroup TOOLS = new SubItemGroup(TOOLS_KEY, MAIN, BCItemStacks.GROUP_TOOL_ITEM); + private static final NamespacedKey MATERIALS_KEY = new NamespacedKey(BetterChests.INSTANCE, "group_materials"); + public static final SubItemGroup MATERIALS = new SubItemGroup(MATERIALS_KEY, MAIN, BCItemStacks.GROUP_MATERIAL_ITEM); } diff --git a/src/main/java/me/mmmjjkx/betterChests/items/BCItemStacks.java b/src/main/java/me/mmmjjkx/betterChests/items/BCItemStacks.java index acb3b54..0059e00 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/BCItemStacks.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/BCItemStacks.java @@ -1,5 +1,6 @@ package me.mmmjjkx.betterChests.items; +import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactivity; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.utils.LoreBuilder; import org.bukkit.Material; @@ -8,9 +9,16 @@ public class BCItemStacks { public static final ItemStack TIP = new CustomItemStack(Material.PAPER, "&6&lTip", "&c&lDon't place too many drawers in one chunk! ", - "The drawers will spawn 3 entities once they were placed."); + "&cThe drawers will spawn 3 entities once they were placed."); public static final ItemStack GROUP_MAIN_ITEM = new CustomItemStack(Material.CHEST, "&6&lBetter Chests"); + public static final ItemStack GROUP_STORAGE_ITEM = new CustomItemStack(Material.BARREL, "&a&lStorages"); + public static final ItemStack GROUP_TOOL_ITEM = new CustomItemStack(Material.BLAZE_ROD, "&b&lTools & Machines"); + public static final ItemStack GROUP_MATERIAL_ITEM = new CustomItemStack(Material.IRON_INGOT, "&b&lMaterials"); + + public static final ItemStack GEAR_WHEEL = new CustomItemStack(Material.REDSTONE, "&aGear Wheel", "&7A tool for crafting"); + public static final ItemStack TIGHTLY_BLISTERING_INGOT = new CustomItemStack(Material.IRON_INGOT, "&eTightly Blistering Ingot", "&7A high-hardness metal", LoreBuilder.radioactive(Radioactivity.VERY_HIGH)); + public static final ItemStack TIGHTLY_BLISTERING_PLATE = new CustomItemStack(Material.IRON_BLOCK, "&eTightly Blistering Plate", "&7A high-hardness metal plate", LoreBuilder.radioactive(Radioactivity.HIGH)); public static final ItemStack LOCATION_RECORDER = new CustomItemStack(Material.COMPASS, "&aLocation Recorder", "&bShift + Right-click to record location", "&bRight-click to open the corresponding machine"); public static final ItemStack CHEST_COLOR_CHANGER = new CustomItemStack(Material.AMETHYST_SHARD, "&aChest Color Changer", "&aRight-click to change the color of the BC chest", "&aShift + Right-click to cycle through colors", "", "&dCurrent color: &6NoColor", "", LoreBuilder.powerCharged(0, 200)); @@ -28,4 +36,13 @@ public class BCItemStacks { public static final ItemStack DRAWER_9 = new CustomItemStack(Material.BARREL, "&aDrawer &6Lvl 9", "&bRight-click grab 64 items (when your hand is empty)", "&bRight-click to store items that you hand in", "&dCapacity: 256M"); public static final ItemStack DRAWER_10 = new CustomItemStack(Material.BARREL, "&aDrawer &6Lvl 10", "&bRight-click grab 64 items (when your hand is empty)", "&bRight-click to store items that you hand in", "&dCapacity: 1B"); public static final ItemStack DRAWER_MAX = new CustomItemStack(Material.BARREL, "&aDrawer &6MAX", "&bRight-click grab 64 items (when your hand is empty)", "&bRight-click to store items that you hand in", "&dCapacity: 2.14B"); + + public static final ItemStack IE_STORAGE_UNIT_1 = new CustomItemStack(Material.OAK_LOG, "&eIE Storage Unit &6Lvl 1", "&bInfinityExpansion-like storage unit", "&dCapacity: 32,000"); + public static final ItemStack IE_STORAGE_UNIT_2 = new CustomItemStack(Material.DARK_OAK_LOG, "&eIE Storage Unit &6Lvl 2", "&bInfinityExpansion-like storage unit", "&dCapacity: 128,000"); + public static final ItemStack IE_STORAGE_UNIT_3 = new CustomItemStack(Material.ACACIA_LOG, "&eIE Storage Unit &6Lvl 3", "&bInfinityExpansion-like storage unit", "&dCapacity: 1,000,000"); + public static final ItemStack IE_STORAGE_UNIT_4 = new CustomItemStack(Material.BIRCH_LOG, "&eIE Storage Unit &6Lvl 4", "&bInfinityExpansion-like storage unit", "&dCapacity: 4,000,000"); + public static final ItemStack IE_STORAGE_UNIT_5 = new CustomItemStack(Material.JUNGLE_LOG, "&eIE Storage Unit &6Lvl 5", "&bInfinityExpansion-like storage unit", "&dCapacity: 64,000,000"); + public static final ItemStack IE_STORAGE_UNIT_6 = new CustomItemStack(Material.MANGROVE_LOG, "&eIE Storage Unit &6Lvl 6", "&bInfinityExpansion-like storage unit", "&dCapacity: 256,000,000"); + public static final ItemStack IE_STORAGE_UNIT_7 = new CustomItemStack(Material.CRIMSON_STEM, "&eIE Storage Unit &6Lvl 7", "&bInfinityExpansion-like storage unit", "&dCapacity: 1,000,000,000"); + public static final ItemStack IE_STORAGE_UNIT_8 = new CustomItemStack(Material.WARPED_STEM, "&eIE Storage Unit &6Lvl 8", "&bInfinityExpansion-like storage unit", "&dCapacity: 2,140,000,000"); } diff --git a/src/main/java/me/mmmjjkx/betterChests/items/BCItems.java b/src/main/java/me/mmmjjkx/betterChests/items/BCItems.java index 6a12d9c..81e9db2 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/BCItems.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/BCItems.java @@ -3,13 +3,16 @@ import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactivity; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; +import io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem; import me.mmmjjkx.betterChests.BCGroups; import me.mmmjjkx.betterChests.BetterChests; import me.mmmjjkx.betterChests.items.chests.OnlyInputChest; import me.mmmjjkx.betterChests.items.chests.OnlyOutputChest; import me.mmmjjkx.betterChests.items.chests.SimpleChest; import me.mmmjjkx.betterChests.items.chests.SimpleDrawer; +import me.mmmjjkx.betterChests.items.chests.ie.IEStorageUnit; import me.mmmjjkx.betterChests.items.machines.ChestDisassembler; import me.mmmjjkx.betterChests.items.tools.ChestColorer; import me.mmmjjkx.betterChests.items.tools.LocationRecorder; @@ -17,14 +20,13 @@ import org.bukkit.inventory.ItemStack; public class BCItems { - private BCItems() {} - public static final SlimefunItem TIP = new SlimefunItem( - BCGroups.MAIN, + BCGroups.STORAGES, new SlimefunItemStack("BC_TTTTTTTTTTTTTTTTTTTTIP_ITEM", BCItemStacks.TIP), RecipeType.NULL, new ItemStack[9]); + // Tools & machines public static final LocationRecorder LOCATION_RECORDER = new LocationRecorder( new SlimefunItemStack("BC_LOCATION_RECORDER", BCItemStacks.LOCATION_RECORDER), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -33,7 +35,55 @@ private BCItems() {} null, SlimefunItems.GPS_TRANSMITTER_3, null, null, SlimefunItems.GPS_MARKER_TOOL, null }); + public static final ChestDisassembler CHEST_DISASSEMBLER = new ChestDisassembler( + new SlimefunItemStack("BC_CHEST_DISASSEMBLER", BCItemStacks.CHEST_DISASSEMBLER), + RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[]{ + null, new ItemStack(Material.IRON_AXE), null, + new ItemStack(Material.IRON_INGOT), new ItemStack(Material.GLASS), new ItemStack(Material.IRON_INGOT), + null, new ItemStack(Material.REDSTONE), null + }); + public static final ChestColorer CHEST_COLORER = new ChestColorer( + new SlimefunItemStack("BC_CHEST_COLORER", BCItemStacks.CHEST_COLOR_CHANGER), + RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[]{ + null, new ItemStack(Material.GLASS), null, + new ItemStack(Material.WHITE_DYE), new ItemStack(Material.STICK), new ItemStack(Material.BLUE_DYE), + new ItemStack(Material.RED_DYE), new ItemStack(Material.REDSTONE_BLOCK), new ItemStack(Material.YELLOW_DYE) + }); + // Materials + public static final SlimefunItem GEAR_WHEEL = new SlimefunItem( + BCGroups.MATERIALS, + new SlimefunItemStack("BC_GEAR_WHEEL", BCItemStacks.GEAR_WHEEL), + RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[]{ + null, new ItemStack(Material.IRON_INGOT), null, + new ItemStack(Material.IRON_INGOT), new ItemStack(Material.REDSTONE), new ItemStack(Material.IRON_INGOT), + null, new ItemStack(Material.IRON_INGOT), null + }); + + public static final SlimefunItem TIGHTLY_BLISTERING_INGOT = new RadioactiveItem( + BCGroups.MATERIALS, + Radioactivity.VERY_HIGH, + new SlimefunItemStack("BC_TIGHTLY_BLISTERING_INGOT", BCItemStacks.TIGHTLY_BLISTERING_INGOT), + RecipeType.ENHANCED_CRAFTING_TABLE, + new ItemStack[]{ + SlimefunItems.SYNTHETIC_EMERALD, SlimefunItems.SYNTHETIC_DIAMOND, SlimefunItems.SYNTHETIC_EMERALD, + SlimefunItems.BLISTERING_INGOT_3, SlimefunItems.BLISTERING_INGOT_3, SlimefunItems.BLISTERING_INGOT_3, + SlimefunItems.SYNTHETIC_EMERALD, SlimefunItems.SYNTHETIC_DIAMOND, SlimefunItems.SYNTHETIC_EMERALD + }); + + public static final SlimefunItem TIGHTLY_BLISTERING_PLATE = new RadioactiveItem( + BCGroups.MATERIALS, + Radioactivity.HIGH, + new SlimefunItemStack("BC_TIGHTLY_BLISTERING_PLATE", BCItemStacks.TIGHTLY_BLISTERING_PLATE), + RecipeType.COMPRESSOR, + new ItemStack[]{ + TIGHTLY_BLISTERING_INGOT.getItem().clone().add(4) + }); + + // Storages public static final SimpleChest CHEST_27 = new SimpleChest( 27, new SlimefunItemStack("BC_CHEST_27", Material.GLASS, "&b&lSimple Chest"), @@ -43,7 +93,6 @@ private BCItems() {} new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.CHEST), new ItemStack(Material.OAK_PLANKS), null, null, null }); - public static final OnlyInputChest CHEST_INPUT_27 = new OnlyInputChest( 27, new SlimefunItemStack("BC_CHEST_INPUT_27", Material.GLASS, "&b&lSimple Chest &c&l(Input Only)"), @@ -53,7 +102,6 @@ null, new ItemStack(Material.HOPPER), null, null, CHEST_27.getItem().clone(), null, null, new ItemStack(Material.REDSTONE), null }); - public static final OnlyOutputChest CHEST_OUTPUT_27 = new OnlyOutputChest( 27, new SlimefunItemStack("BC_CHEST_OUTPUT_27", Material.GLASS, "&b&lSimple Chest &c&l(Output Only)"), @@ -63,7 +111,6 @@ null, new ItemStack(Material.REDSTONE), null, null, CHEST_27.getItem().clone(), null, null, new ItemStack(Material.HOPPER), null }); - public static final SimpleChest CHEST_36 = new SimpleChest( 36, new SlimefunItemStack("BC_CHEST_36", Material.GLASS, "&b&lBig Chest"), @@ -73,7 +120,6 @@ null, new ItemStack(Material.HOPPER), null new ItemStack(Material.OAK_PLANKS), CHEST_27.getItem().clone(), new ItemStack(Material.OAK_PLANKS), null, new ItemStack(Material.IRON_INGOT), null }); - public static final OnlyInputChest CHEST_INPUT_36 = new OnlyInputChest( 36, new SlimefunItemStack("BC_CHEST_INPUT_36", Material.GLASS, "&b&lBig Chest &c&l(Input Only)"), @@ -83,7 +129,6 @@ null, new ItemStack(Material.HOPPER), null, null, CHEST_36.getItem().clone(), null, null, new ItemStack(Material.REDSTONE), null }); - public static final OnlyOutputChest CHEST_OUTPUT_36 = new OnlyOutputChest( 36, new SlimefunItemStack("BC_CHEST_OUTPUT_36", Material.GLASS, "&b&lBig Chest &c&l(Output Only)"), @@ -93,7 +138,6 @@ null, new ItemStack(Material.REDSTONE), null, null, CHEST_36.getItem().clone(), null, null, new ItemStack(Material.HOPPER), null }); - public static final SimpleChest CHEST_45 = new SimpleChest( 45, new SlimefunItemStack("BC_CHEST_45", Material.GLASS, "&b&lBigger Chest"), @@ -103,7 +147,6 @@ null, new ItemStack(Material.HOPPER), null new ItemStack(Material.OAK_PLANKS), CHEST_36.getItem().clone(), new ItemStack(Material.OAK_PLANKS), null, SlimefunItems.HARDENED_METAL_INGOT.clone(), null }); - public static final OnlyInputChest CHEST_INPUT_45 = new OnlyInputChest( 45, new SlimefunItemStack("BC_CHEST_INPUT_45", Material.GLASS, "&b&lBigger Chest &c&l(Input Only)"), @@ -113,7 +156,6 @@ null, new ItemStack(Material.HOPPER), null, null, CHEST_45.getItem().clone(), null, null, new ItemStack(Material.REDSTONE), null }); - public static final OnlyOutputChest CHEST_OUTPUT_45 = new OnlyOutputChest( 45, new SlimefunItemStack("BC_CHEST_OUTPUT_45", Material.GLASS, "&b&lBigger Chest &c&l(Output Only)"), @@ -123,7 +165,6 @@ null, new ItemStack(Material.REDSTONE), null, null, CHEST_45.getItem().clone(), null, null, new ItemStack(Material.HOPPER), null }); - public static final SimpleChest CHEST_54 = new SimpleChest( 54, new SlimefunItemStack("BC_CHEST_54", Material.GLASS, "&b&lThe Biggest Chest"), @@ -133,7 +174,6 @@ null, new ItemStack(Material.HOPPER), null new ItemStack(Material.OAK_PLANKS), CHEST_45.getItem().clone(), new ItemStack(Material.OAK_PLANKS), null, SlimefunItems.REINFORCED_ALLOY_INGOT.clone(), null }); - public static final OnlyInputChest CHEST_INPUT_54 = new OnlyInputChest( 54, new SlimefunItemStack("BC_CHEST_INPUT_54", Material.GLASS, "&b&lThe Biggest Chest &c&l(Input Only)"), @@ -143,7 +183,6 @@ null, new ItemStack(Material.HOPPER), null, null, CHEST_54.getItem().clone(), null, null, new ItemStack(Material.REDSTONE), null }); - public static final OnlyOutputChest CHEST_OUTPUT_54 = new OnlyOutputChest( 54, new SlimefunItemStack("BC_CHEST_OUTPUT_54", Material.GLASS, "&b&lThe Biggest Chest &c&l(Output Only)"), @@ -154,33 +193,15 @@ null, new ItemStack(Material.REDSTONE), null, null, new ItemStack(Material.HOPPER), null }); - public static final ChestDisassembler CHEST_DISASSEMBLER = new ChestDisassembler( - new SlimefunItemStack("BC_CHEST_DISASSEMBLER", BCItemStacks.CHEST_DISASSEMBLER), - RecipeType.ENHANCED_CRAFTING_TABLE, - new ItemStack[]{ - null, new ItemStack(Material.IRON_AXE), null, - new ItemStack(Material.IRON_INGOT), new ItemStack(Material.GLASS), new ItemStack(Material.IRON_INGOT), - null, new ItemStack(Material.REDSTONE), null - }); - - public static final ChestColorer CHEST_COLORER = new ChestColorer( - new SlimefunItemStack("BC_CHEST_COLORER", BCItemStacks.CHEST_COLOR_CHANGER), - RecipeType.ENHANCED_CRAFTING_TABLE, - new ItemStack[]{ - null, new ItemStack(Material.GLASS), null, - new ItemStack(Material.WHITE_DYE), new ItemStack(Material.STICK), new ItemStack(Material.BLUE_DYE), - new ItemStack(Material.RED_DYE), new ItemStack(Material.REDSTONE_BLOCK), new ItemStack(Material.YELLOW_DYE) - }); - + // Drawers public static final SimpleDrawer DRAWER_1 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_1", BCItemStacks.DRAWER_1), RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{ new ItemStack(Material.OAK_LOG), new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.OAK_LOG), - new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.CHEST), new ItemStack(Material.OAK_PLANKS), + new ItemStack(Material.OAK_LOG), new ItemStack(Material.CHEST), new ItemStack(Material.OAK_LOG), new ItemStack(Material.OAK_LOG), new ItemStack(Material.LEVER), new ItemStack(Material.OAK_LOG) }, 1024); - public static final SimpleDrawer DRAWER_2 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_2", BCItemStacks.DRAWER_2), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -189,7 +210,6 @@ null, new ItemStack(Material.GLASS), null, new ItemStack(Material.CHEST), DRAWER_1.getItem().clone(), new ItemStack(Material.CHEST), new ItemStack(Material.OAK_LOG), new ItemStack(Material.LEVER), new ItemStack(Material.OAK_LOG) }, 4096); - public static final SimpleDrawer DRAWER_3 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_3", BCItemStacks.DRAWER_3), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -198,7 +218,6 @@ null, new ItemStack(Material.GLASS), null, new ItemStack(Material.CHEST), DRAWER_2.getItem().clone(), new ItemStack(Material.CHEST), new ItemStack(Material.IRON_INGOT), new ItemStack(Material.LEVER), new ItemStack(Material.IRON_INGOT) }, 16384); - public static final SimpleDrawer DRAWER_4 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_4", BCItemStacks.DRAWER_4), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -207,7 +226,6 @@ null, new ItemStack(Material.GLASS), null, CHEST_36.getItem().clone(), DRAWER_3.getItem().clone(), CHEST_36.getItem().clone(), new ItemStack(Material.DIAMOND), new ItemStack(Material.LEVER), new ItemStack(Material.DIAMOND) }, 262_000); - public static final SimpleDrawer DRAWER_5 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_5", BCItemStacks.DRAWER_5), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -216,7 +234,6 @@ null, new ItemStack(Material.GLASS), null, CHEST_45.getItem().clone(), DRAWER_4.getItem().clone(), CHEST_45.getItem().clone(), SlimefunItems.SYNTHETIC_SAPPHIRE.clone(), new ItemStack(Material.REDSTONE_BLOCK), SlimefunItems.SYNTHETIC_SAPPHIRE.clone() }, 1_000_000); - public static final SimpleDrawer DRAWER_6 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_6", BCItemStacks.DRAWER_6), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -225,7 +242,6 @@ null, new ItemStack(Material.GLASS), null, CHEST_54.getItem().clone(), DRAWER_5.getItem().clone(), CHEST_54.getItem().clone(), SlimefunItems.SYNTHETIC_EMERALD.clone(), new ItemStack(Material.REDSTONE_BLOCK), SlimefunItems.SYNTHETIC_EMERALD.clone() }, 4_000_000); - public static final SimpleDrawer DRAWER_7 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_7", BCItemStacks.DRAWER_7), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -234,7 +250,6 @@ null, new ItemStack(Material.GLASS), null, CHEST_54.getItem().clone(), DRAWER_6.getItem().clone(), CHEST_54.getItem().clone(), SlimefunItems.SYNTHETIC_EMERALD.clone(), new ItemStack(Material.REDSTONE_BLOCK), SlimefunItems.SYNTHETIC_EMERALD.clone() }, 16_000_000); - public static final SimpleDrawer DRAWER_8 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_8", BCItemStacks.DRAWER_8), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -243,7 +258,6 @@ null, new ItemStack(Material.GLASS), null, CHEST_54.getItem().clone(), DRAWER_7.getItem().clone(), CHEST_54.getItem().clone(), SlimefunItems.SYNTHETIC_EMERALD.clone(), new ItemStack(Material.REDSTONE_BLOCK), SlimefunItems.SYNTHETIC_EMERALD.clone() }, 64_000_000); - public static final SimpleDrawer DRAWER_9 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_9", BCItemStacks.DRAWER_9), RecipeType.ENHANCED_CRAFTING_TABLE, @@ -252,28 +266,108 @@ null, new ItemStack(Material.GLASS), null, CHEST_54.getItem().clone(), DRAWER_8.getItem().clone(), CHEST_54.getItem().clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.REDSTONE_ALLOY.clone(), SlimefunItems.REINFORCED_PLATE.clone() }, 256_000_000); - public static final SimpleDrawer DRAWER_10 = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_10", BCItemStacks.DRAWER_10), RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{ - SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.BLISTERING_INGOT_3.clone(), SlimefunItems.REINFORCED_PLATE.clone(), + SlimefunItems.REINFORCED_PLATE.clone(), TIGHTLY_BLISTERING_INGOT.getItem().clone(), SlimefunItems.REINFORCED_PLATE.clone(), CHEST_54.getItem().clone(), DRAWER_9.getItem().clone(), CHEST_54.getItem().clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.REDSTONE_ALLOY.clone(), SlimefunItems.REINFORCED_PLATE.clone() }, 1_000_000_000); - public static final SimpleDrawer DRAWER_MAX = new SimpleDrawer( new SlimefunItemStack("BC_DRAWER_MAX", BCItemStacks.DRAWER_MAX), RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[]{ - SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.BLISTERING_INGOT_3.clone(), SlimefunItems.REINFORCED_PLATE.clone(), + SlimefunItems.REINFORCED_PLATE.clone(), TIGHTLY_BLISTERING_PLATE.getItem().clone(), SlimefunItems.REINFORCED_PLATE.clone(), CHEST_54.getItem().clone(), DRAWER_10.getItem().clone(), CHEST_54.getItem().clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.REDSTONE_ALLOY.clone(), SlimefunItems.REINFORCED_PLATE.clone() }, 2_140_000_000); + // IE Storage units + public static final IEStorageUnit IE_STORAGE_UNIT_1 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_1", BCItemStacks.IE_STORAGE_UNIT_1), + 32_000, + new ItemStack[]{ + SlimefunItems.COPPER_INGOT.clone(), SlimefunItems.COPPER_INGOT.clone(), SlimefunItems.COPPER_INGOT.clone(), + GEAR_WHEEL.getItem().clone(), new ItemStack(Material.CHEST), GEAR_WHEEL.getItem().clone(), + SlimefunItems.ELECTRIC_MOTOR.clone(), new ItemStack(Material.OAK_LOG), SlimefunItems.SILICON.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_2 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_2", BCItemStacks.IE_STORAGE_UNIT_2), + 128_000, + new ItemStack[]{ + SlimefunItems.ALUMINUM_BRONZE_INGOT.clone(), SlimefunItems.ALUMINUM_BRONZE_INGOT.clone(), SlimefunItems.ALUMINUM_BRONZE_INGOT.clone(), + GEAR_WHEEL.getItem().clone(), IE_STORAGE_UNIT_1.getItem().clone(), GEAR_WHEEL.getItem().clone(), + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.HARDENED_METAL_INGOT.clone(), SlimefunItems.SYNTHETIC_EMERALD.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_3 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_3", BCItemStacks.IE_STORAGE_UNIT_3), + 1_000_000, + new ItemStack[]{ + SlimefunItems.HARDENED_METAL_INGOT.clone(), SlimefunItems.HARDENED_METAL_INGOT.clone(), SlimefunItems.HARDENED_METAL_INGOT.clone(), + GEAR_WHEEL.getItem().clone(), IE_STORAGE_UNIT_2.getItem().clone(), GEAR_WHEEL.getItem().clone(), + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.REINFORCED_ALLOY_INGOT.clone(), SlimefunItems.SYNTHETIC_DIAMOND.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_4 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_4", BCItemStacks.IE_STORAGE_UNIT_4), + 4_000_000, + new ItemStack[]{ + SlimefunItems.REINFORCED_ALLOY_INGOT.clone(), SlimefunItems.REINFORCED_ALLOY_INGOT.clone(), SlimefunItems.REINFORCED_ALLOY_INGOT.clone(), + SlimefunItems.REDSTONE_ALLOY, IE_STORAGE_UNIT_3.getItem().clone(), SlimefunItems.REDSTONE_ALLOY, + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.SYNTHETIC_DIAMOND.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_5 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_5", BCItemStacks.IE_STORAGE_UNIT_5), + 64_000_000, + new ItemStack[]{ + SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.REINFORCED_PLATE.clone(), + SlimefunItems.REDSTONE_ALLOY, IE_STORAGE_UNIT_4.getItem().clone(), SlimefunItems.REDSTONE_ALLOY, + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.ANDROID_MEMORY_CORE.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_6 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_6", BCItemStacks.IE_STORAGE_UNIT_6), + 256_000_000, + new ItemStack[]{ + SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.BLISTERING_INGOT.clone(), SlimefunItems.REINFORCED_PLATE.clone(), + SlimefunItems.REDSTONE_ALLOY, IE_STORAGE_UNIT_5.getItem().clone(), SlimefunItems.REDSTONE_ALLOY, + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.ANDROID_MEMORY_CORE.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_7 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_7", BCItemStacks.IE_STORAGE_UNIT_7), + 1_000_000_000, + new ItemStack[]{ + SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.BLISTERING_INGOT_2.clone(), SlimefunItems.REINFORCED_PLATE.clone(), + SlimefunItems.REDSTONE_ALLOY, IE_STORAGE_UNIT_6.getItem().clone(), SlimefunItems.REDSTONE_ALLOY, + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.ANDROID_MEMORY_CORE.clone() + }); + + public static final IEStorageUnit IE_STORAGE_UNIT_8 = new IEStorageUnit( + new SlimefunItemStack("BC_IE_STORAGE_UNIT_8", BCItemStacks.IE_STORAGE_UNIT_8), + 2_140_000_000, + new ItemStack[]{ + TIGHTLY_BLISTERING_INGOT.getItem().clone(), SlimefunItems.BLISTERING_INGOT_3.clone(), TIGHTLY_BLISTERING_INGOT.getItem().clone(), + SlimefunItems.REDSTONE_ALLOY, IE_STORAGE_UNIT_7.getItem().clone(), SlimefunItems.REDSTONE_ALLOY, + SlimefunItems.ELECTRIC_MOTOR.clone(), SlimefunItems.REINFORCED_PLATE.clone(), SlimefunItems.ANDROID_MEMORY_CORE.clone() + }); + + + private BCItems() { + } + public static void registerItems() { TIP.register(BetterChests.INSTANCE); + TIGHTLY_BLISTERING_INGOT.register(BetterChests.INSTANCE); + TIGHTLY_BLISTERING_PLATE.register(BetterChests.INSTANCE); + GEAR_WHEEL.register(BetterChests.INSTANCE); + + CHEST_DISASSEMBLER.register(BetterChests.INSTANCE); LOCATION_RECORDER.register(BetterChests.INSTANCE); CHEST_COLORER.register(BetterChests.INSTANCE); @@ -292,8 +386,6 @@ public static void registerItems() { CHEST_OUTPUT_45.register(BetterChests.INSTANCE); CHEST_OUTPUT_54.register(BetterChests.INSTANCE); - CHEST_DISASSEMBLER.register(BetterChests.INSTANCE); - DRAWER_1.register(BetterChests.INSTANCE); DRAWER_2.register(BetterChests.INSTANCE); DRAWER_3.register(BetterChests.INSTANCE); @@ -305,5 +397,14 @@ public static void registerItems() { DRAWER_9.register(BetterChests.INSTANCE); DRAWER_10.register(BetterChests.INSTANCE); DRAWER_MAX.register(BetterChests.INSTANCE); + + IE_STORAGE_UNIT_1.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_2.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_3.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_4.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_5.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_6.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_7.register(BetterChests.INSTANCE); + IE_STORAGE_UNIT_8.register(BetterChests.INSTANCE); } } diff --git a/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleChest.java b/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleChest.java index 0fc59e9..0a512b0 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleChest.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleChest.java @@ -24,7 +24,7 @@ public class SimpleChest extends SlimefunItem implements InventoryBlock { private final int size; public SimpleChest(int size, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { - super(BCGroups.MAIN, item, recipeType, recipe); + super(BCGroups.STORAGES, item, recipeType, recipe); this.size = size; diff --git a/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleDrawer.java b/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleDrawer.java index f0e3137..5840953 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleDrawer.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/chests/SimpleDrawer.java @@ -17,7 +17,10 @@ import me.mmmjjkx.betterChests.BetterChests; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TranslatableComponent; -import org.bukkit.*; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.TileState; @@ -51,7 +54,7 @@ public class SimpleDrawer extends SlimefunItem implements NotHopperable { private final int capacity; public SimpleDrawer(SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, int capacity) { - super(BCGroups.MAIN, item, recipeType, recipe); + super(BCGroups.STORAGES, item, recipeType, recipe); this.capacity = capacity; @@ -287,7 +290,7 @@ private EntityContainer tryGetContainer(final Location barrelLoc) { } } ); - + ItemDisplay item = itemA.get(); TextDisplay itemName = itemNameA.get(); TextDisplay itemCount = itemCountA.get(); @@ -400,6 +403,7 @@ private MetadataValue getMetadata(Metadatable m, String key) { /** * Get the capacity of the drawer. + * * @return the capacity of the drawer. */ public int getCapacity() { @@ -409,8 +413,9 @@ public int getCapacity() { /** * Add items to the drawer. * (For hooks) + * * @param barrelLoc the location of the drawer - * @param item the item to add + * @param item the item to add * @return a pair of a boolean indicating whether the item was added and an integer indicating the remaining number of items in the drawer. */ public Pair addItem(Location barrelLoc, ItemStack item) { @@ -482,6 +487,7 @@ public Pair addItem(Location barrelLoc, ItemStack item) { /** * Get the item currently being stored in the drawer. * (For hooks) + * * @param barrelLoc the location of the drawer * @return the item being stored, or null if there is no item. */ @@ -497,8 +503,9 @@ public ItemStack getStoringItem(Location barrelLoc) { /** * Take items from the drawer. * (For hooks) + * * @param barrelLoc the location of the drawer - * @param count the number of items to take + * @param count the number of items to take * @return the item taken, or null if there is no item or less than the specified number of items in the drawer. */ @CanIgnoreReturnValue @@ -548,5 +555,6 @@ public ItemStack takeItem(Location barrelLoc, int count) { return copy; } - private record EntityContainer(ItemDisplay item, TextDisplay itemName, TextDisplay itemCount) { } + private record EntityContainer(ItemDisplay item, TextDisplay itemName, TextDisplay itemCount) { + } } diff --git a/src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageCache.java b/src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageCache.java new file mode 100644 index 0000000..1cd9dc2 --- /dev/null +++ b/src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageCache.java @@ -0,0 +1,486 @@ +package me.mmmjjkx.betterChests.items.chests.ie; + +import io.github.thebusybiscuit.slimefun4.libraries.dough.common.ChatColors; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.ItemUtils; +import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; +import me.mmmjjkx.betterChests.BetterChests; +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +import me.mrCookieSlime.Slimefun.api.BlockStorage; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.block.data.type.WallSign; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.persistence.PersistentDataType; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import static me.mmmjjkx.betterChests.items.chests.ie.IEStorageUnit.*; + +/** + * Represents a single storage unit with cached data + * + * @author Mooy1, mmmjjkx + */ +@SuppressWarnings("deprecation") +public final class IEStorageCache { + + /* Menu strings */ + private static final String EMPTY_DISPLAY_NAME = ChatColor.WHITE + "Empty"; + private static final String VOID_EXCESS_TRUE = ChatColors.color("&7Void Excess:&e true"); + private static final String VOID_EXCESS_FALSE = ChatColors.color("&7Void Excess:&e false"); + + /* BlockStorage keys */ + private static final String STORED_AMOUNT = "stored"; // amount key in block data + private static final String VOID_EXCESS = "void_excess"; // void excess true or null key + + /* Menu Items */ + private static final ItemStack EMPTY_ITEM = new CustomItemStack(Material.BARRIER, meta -> { + meta.setDisplayName(ChatColor.WHITE + "Empty"); + meta.getPersistentDataContainer().set(EMPTY_KEY, PersistentDataType.BYTE, (byte) 1); + }); + + /* Space Pattern for Sign Display Names */ + private static final Pattern SPACE = Pattern.compile(" "); + + /* Instance Constants */ + private final IEStorageUnit storageUnit; + private final BlockMenu menu; + + /* Instance Variables */ + private final String[] signDisplay = new String[2]; + private String displayName; + private Material material; + private ItemMeta meta; + private boolean voidExcess; + + private int amount; + + IEStorageCache(IEStorageUnit storageUnit, BlockMenu menu) { + this.storageUnit = storageUnit; + this.menu = menu; + + // load data + reloadData(); + + if (isEmpty()) { + // empty + setEmptyDisplayName(); + menu.replaceExistingItem(DISPLAY_SLOT, EMPTY_ITEM); + } else { + // something is stored + ItemStack display = menu.getItemInSlot(DISPLAY_SLOT); + if (display != null) { + ItemMeta copy = display.getItemMeta(); + // fix if they somehow store the empty item + if (copy.getPersistentDataContainer().has(EMPTY_KEY, PersistentDataType.BYTE)) { + // attempt to recover the correct item from output + ItemStack output = menu.getItemInSlot(OUTPUT_SLOT); + if (output != null) { + setStored(output); + menu.replaceExistingItem(OUTPUT_SLOT, null); + } else { + // no output to recover + menu.replaceExistingItem(DISPLAY_SLOT, EMPTY_ITEM); + setEmptyDisplayName(); + this.amount = 0; + } + } else { + // load the item in menu + load(display, copy); + } + } + } + + // void excess handler + menu.addMenuClickHandler(STATUS_SLOT, (p, slot, item, action) -> { + this.voidExcess = !this.voidExcess; + BlockStorage.addBlockInfo(this.menu.getLocation(), VOID_EXCESS, this.voidExcess ? "true" : null); + ItemMeta meta = item.getItemMeta(); + List lore = meta.getLore(); + lore.set(1, this.voidExcess ? VOID_EXCESS_TRUE : VOID_EXCESS_FALSE); + meta.setLore(lore); + item.setItemMeta(meta); + return false; + }); + + // interact handler + menu.addMenuClickHandler(INTERACT_SLOT, (p, slot, item, action) -> { + if (this.amount == 1) { + if (action.isShiftClicked() && !action.isRightClicked()) { + depositAll(p); + } else { + withdrawLast(p); + } + } else if (!isEmpty()) { + if (action.isRightClicked()) { + if (action.isShiftClicked()) { + withdraw(p, this.amount - 1); + } else { + withdraw(p, Math.min(this.material.getMaxStackSize(), this.amount - 1)); + } + } else { + if (action.isShiftClicked()) { + depositAll(p); + } else { + withdraw(p, 1); + } + } + } + return false; + }); + + // load status slot + updateStatus(); + } + + private static boolean checkWallSign(Block sign, Block block) { + return SlimefunTag.WALL_SIGNS.isTagged(sign.getType()) + && sign.getRelative(((WallSign) sign.getBlockData()).getFacing().getOppositeFace()).equals(block); + } + + private void setDisplayName(String name) { + this.displayName = name; + + int len = name.length(); + if (len == 0) { + this.signDisplay[0] = ""; + this.signDisplay[1] = ""; + return; + } + + String color; + if (len >= 2 && name.charAt(0) == ChatColor.COLOR_CHAR) { + char second = name.charAt(1); + if (len >= 14 && second == 'x') { + color = name.substring(0, 14); + } else { + color = new String(new char[]{ + ChatColor.COLOR_CHAR, second + }); + } + } else { + color = null; + } + + if (name.length() <= 15) { + this.signDisplay[0] = color != null ? name : ChatColor.WHITE + name; + this.signDisplay[1] = ""; + return; + } + + String[] words = SPACE.split(name); + int i = 1; + StringBuilder firstLine = new StringBuilder(); + if (color == null) { + firstLine.append(ChatColor.WHITE); + } + firstLine.append(words[0]); + while (i < words.length && words[i].length() + firstLine.length() < 15) { + firstLine.append(' ').append(words[i++]); + } + this.signDisplay[0] = firstLine.toString(); + + if (i < words.length) { + StringBuilder secondLine = new StringBuilder(); + String first = words[i++]; + if (first.length() <= 1 || first.charAt(0) != ChatColor.COLOR_CHAR) { + if (color == null) { + secondLine.append(ChatColor.WHITE); + } else { + secondLine.append(color); + } + } + secondLine.append(first); + while (i < words.length) { + secondLine.append(' ').append(words[i++]); + } + this.signDisplay[1] = secondLine.toString(); + } else { + this.signDisplay[1] = ""; + } + } + + private void setEmptyDisplayName() { + this.displayName = EMPTY_DISPLAY_NAME; + this.signDisplay[0] = EMPTY_DISPLAY_NAME; + this.signDisplay[1] = ""; + } + + void destroy(BlockBreakEvent e, List drops) { + // add output slot + ItemStack output = this.menu.getItemInSlot(OUTPUT_SLOT); + if (output != null && matches(output)) { + int add = Math.min(this.storageUnit.max - this.amount, output.getAmount()); + if (add != 0) { + this.amount += add; + output.setAmount(output.getAmount() - add); + } + } + + Block b = e.getBlock(); + ItemStack drop = this.storageUnit.getItem().clone(); + drop.setItemMeta(IEStorageUnit.saveToStack(drop.getItemMeta(), this.storageUnit.getDisplayingItem(b), this.displayName, this.amount)); + e.getPlayer().sendMessage(ChatColor.GREEN + "Stored items transferred to dropped item"); + drops.add(drop); + b.removeMetadata("ie_item", BetterChests.INSTANCE); + } + + void reloadData() { + Config config = BlockStorage.getLocationInfo(this.menu.getLocation()); + String amt = config.getString(STORED_AMOUNT); + this.amount = amt == null ? 0 : Integer.parseInt(amt); + this.voidExcess = "true".equals(config.getString(VOID_EXCESS)); + } + + void load(ItemStack stored, ItemMeta copy) { + this.menu.replaceExistingItem(DISPLAY_SLOT, stored); + + // remove the display key from copy + copy.getPersistentDataContainer().remove(DISPLAY_KEY); + + // check if the copy has anything besides the display key + if (copy.equals(Bukkit.getItemFactory().getItemMeta(stored.getType()))) { + this.meta = null; + } else { + this.meta = copy; + } + setDisplayName(ItemUtils.getItemName(stored)); + this.material = stored.getType(); + } + + void input() { + ItemStack input = this.menu.getItemInSlot(INPUT_SLOT); + if (input == null) { + return; + } + if (isEmpty()) { + // set the stored item to input + this.amount = input.getAmount(); + setStored(input); + this.menu.replaceExistingItem(INPUT_SLOT, null, false); + } else if (matches(input)) { + if (this.voidExcess) { + // input and void excess + if (this.amount < this.storageUnit.max) { + this.amount = Math.min(this.amount + input.getAmount(), this.storageUnit.max); + } + input.setAmount(0); + } else if (this.amount < this.storageUnit.max) { + // input as much as possible + if (input.getAmount() + this.amount >= this.storageUnit.max) { + // last item + input.setAmount(input.getAmount() - (this.storageUnit.max - this.amount)); + this.amount = this.storageUnit.max; + } else { + this.amount += input.getAmount(); + input.setAmount(0); + } + } + } + } + + private void output() { + if (this.amount == 0) { + return; + } + ItemStack outputSlot = this.menu.getItemInSlot(OUTPUT_SLOT); + if (outputSlot == null) { + if (this.amount == 1) { + this.menu.replaceExistingItem(OUTPUT_SLOT, createItem(1), false); + setEmpty(); + } else { + int amt = Math.min(this.material.getMaxStackSize(), this.amount - 1); + this.menu.replaceExistingItem(OUTPUT_SLOT, createItem(amt), false); + this.amount -= amt; + } + } else if (this.amount > 1) { + int amt = Math.min(this.material.getMaxStackSize() - outputSlot.getAmount(), this.amount - 1); + if (amt != 0 && matches(outputSlot)) { + outputSlot.setAmount(outputSlot.getAmount() + amt); + this.amount -= amt; + } + } + } + + void tick(Block block) { + // input output + input(); + output(); + + // store amount + BlockStorage.addBlockInfo(this.menu.getLocation(), STORED_AMOUNT, String.valueOf(this.amount)); + + // status + if (this.menu.hasViewer()) { + updateStatus(); + } + + // signs + Block check = block.getRelative(0, 1, 0); + if (SlimefunTag.SIGNS.isTagged(check.getType()) + || checkWallSign(check = block.getRelative(1, 0, 0), block) + || checkWallSign(check = block.getRelative(-1, 0, 0), block) + || checkWallSign(check = block.getRelative(0, 0, 1), block) + || checkWallSign(check = block.getRelative(0, 0, -1), block) + ) { + Sign sign = (Sign) check.getState(); + sign.setLine(0, this.signDisplay[0]); + sign.setLine(1, this.signDisplay[1]); + sign.setLine(2, ChatColor.GRAY + "------------"); + sign.setLine(3, ChatColor.YELLOW.toString() + this.amount); + sign.update(); + } + } + + private void updateStatus() { + this.menu.replaceExistingItem(STATUS_SLOT, new CustomItemStack(Material.CYAN_STAINED_GLASS_PANE, meta -> { + meta.setDisplayName(ChatColor.AQUA + "Status"); + List lore = new ArrayList<>(); + if (this.amount == 0) { + lore.add(ChatColors.color("&6Stored: &e0 / " + format(this.storageUnit.max) + " &7(0%)")); + } else { + lore.add(ChatColors.color("&6Stored: &e" + format(this.amount) + + " / " + format(this.storageUnit.max) + + " &7(" + format((double) this.amount * 100.D / this.storageUnit.max) + "%)" + )); + } + lore.add(this.voidExcess ? VOID_EXCESS_TRUE : VOID_EXCESS_FALSE); + lore.add(ChatColor.GRAY + "(Click to toggle)"); + meta.setLore(lore); + }), false); + } + + private void setStored(ItemStack input) { + this.meta = input.hasItemMeta() ? input.getItemMeta() : null; + setDisplayName(ItemUtils.getItemName(input)); + this.material = input.getType(); + + // add the display key to the display input and set amount 1 + ItemMeta meta = input.getItemMeta(); + meta.getPersistentDataContainer().set(DISPLAY_KEY, PersistentDataType.BYTE, (byte) 1); + input.setItemMeta(meta); + input.setAmount(1); + + this.menu.replaceExistingItem(DISPLAY_SLOT, input); + menu.getLocation().getBlock().setMetadata("ie_item", new FixedMetadataValue(BetterChests.INSTANCE, input)); + } + + private void setEmpty() { + setEmptyDisplayName(); + this.meta = null; + this.material = null; + this.menu.replaceExistingItem(DISPLAY_SLOT, EMPTY_ITEM); + this.amount = 0; + menu.getLocation().getBlock().removeMetadata("ie_item", BetterChests.INSTANCE); + } + + boolean matches(ItemStack item) { + return item.getType() == this.material + && item.hasItemMeta() == (this.meta != null) + && (this.meta == null || this.meta.equals(item.getItemMeta())); + } + + private ItemStack createItem(int amount) { + ItemStack item = new ItemStack(this.material, amount); + if (this.meta != null) { + item.setItemMeta(this.meta); + } + return item; + } + + boolean isEmpty() { + return this.amount == 0; + } + + private void withdraw(Player p, int withdraw) { + if (this.material.getMaxStackSize() == 64) { + ItemStack remaining = p.getInventory().addItem(createItem(withdraw)).get(0); + if (remaining != null) { + if (remaining.getAmount() != withdraw) { + this.amount += remaining.getAmount() - withdraw; + } + } else { + this.amount -= withdraw; + } + return; + } + + Inventory inv = p.getInventory(); + int toWithdraw = withdraw; + do { + int amt = Math.min(this.material.getMaxStackSize(), toWithdraw); + ItemStack remaining = inv.addItem(createItem(amt)).get(0); + if (remaining != null) { + toWithdraw -= amt - remaining.getAmount(); + break; + } else { + toWithdraw -= amt; + } + } + while (toWithdraw > 0); + if (toWithdraw != withdraw) { + this.amount += toWithdraw - withdraw; + } + } + + private void withdrawLast(Player p) { + if (p.getInventory().addItem(createItem(1)).get(0) == null) { + setEmpty(); + } + } + + private void depositAll(Player p) { + depositAll(p.getInventory().getStorageContents()); + } + + public void depositAll(ItemStack[] itemStacks) { + depositAll(itemStacks, false); + } + + public void depositAll(ItemStack[] itemStacks, boolean observeVoiding) { + if (this.amount < this.storageUnit.max) { + for (ItemStack item : itemStacks) { + if (item != null && matches(item)) { + if (item.getAmount() + this.amount >= this.storageUnit.max) { + // last item + item.setAmount(item.getAmount() - (this.storageUnit.max - this.amount)); + this.amount = this.storageUnit.max; + } else { + this.amount += item.getAmount(); + item.setAmount(0); + } + } + } + } + if (observeVoiding && this.voidExcess) { + for (ItemStack item : itemStacks) { + if (item != null && matches(item)) { + item.setAmount(0); + } + } + } + } + + public void amount(int amount) { + this.amount = amount; + } + + private static final DecimalFormat FORMAT = new DecimalFormat("###,###,###,###,###,###.#"); + + private String format(double num) { + return FORMAT.format(num); + } +} \ No newline at end of file diff --git a/src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageUnit.java b/src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageUnit.java new file mode 100644 index 0000000..fd264f9 --- /dev/null +++ b/src/main/java/me/mmmjjkx/betterChests/items/chests/ie/IEStorageUnit.java @@ -0,0 +1,295 @@ +package me.mmmjjkx.betterChests.items.chests.ie; + +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.core.attributes.DistinctiveItem; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler; +import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.libraries.dough.collections.Pair; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; +import io.github.thebusybiscuit.slimefun4.libraries.dough.items.ItemUtils; +import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction; +import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; +import me.mmmjjkx.betterChests.BCGroups; +import me.mmmjjkx.betterChests.BetterChests; +import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +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.inventory.BlockMenu; +import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset; +import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu; +import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.persistence.PersistentDataAdapterContext; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.util.io.BukkitObjectInputStream; +import org.bukkit.util.io.BukkitObjectOutputStream; +import org.jetbrains.annotations.NotNull; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.*; + +/** + * A block that stored large amounts of one item + * + * @author Mooy1, mmmjjkx + */ +@ParametersAreNonnullByDefault +@SuppressWarnings("deprecation") +public final class IEStorageUnit extends SlimefunItem implements InventoryBlock, DistinctiveItem { + + static final NamespacedKey EMPTY_KEY = new NamespacedKey(BetterChests.INSTANCE, "empty"); // key for empty item + static final NamespacedKey DISPLAY_KEY = new NamespacedKey(BetterChests.INSTANCE, "display"); // key for display item + private static final NamespacedKey ITEM_KEY = new NamespacedKey(BetterChests.INSTANCE, "item"); // item key for item pdc + private static final NamespacedKey AMOUNT_KEY = new NamespacedKey(BetterChests.INSTANCE, "stored"); // amount key for item pdc + + static final int INPUT_SLOT = 10; + static final int DISPLAY_SLOT = 13; + static final int STATUS_SLOT = 4; + static final int OUTPUT_SLOT = 16; + static final int INTERACT_SLOT = 22; + + private static final ItemStack INTERACTION_ITEM = new CustomItemStack(Material.LIME_STAINED_GLASS_PANE, + "&aQuick Actions", + "&bLeft Click: &7Withdraw 1 item", + "&bRight Click: &7Withdraw 1 stack", + "&bShift Left Click: &7Deposit inventory", + "&bShift Right Click: &7Withdraw inventory" + ); + private static final ItemStack LOADING_ITEM = new CustomItemStack(Material.CYAN_STAINED_GLASS_PANE, + "&bStatus", + "&7Loading..." + ); + + final int max; + private final Map caches = new HashMap<>(); + + public static final PersistentDataType ITEM_STACK = new PersistentDataType<>() { + @Override + public @NotNull Class getPrimitiveType() { + return byte[].class; + } + + @Override + public @NotNull Class getComplexType() { + return ItemStack.class; + } + + @Override + public byte @NotNull [] toPrimitive(@NotNull ItemStack itemStack, @NotNull PersistentDataAdapterContext persistentDataAdapterContext) { + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + try (BukkitObjectOutputStream output = new BukkitObjectOutputStream(bytes)) { + output.writeObject(itemStack); + } catch (Exception e) { + e.printStackTrace(); + } + return bytes.toByteArray(); + } + + @Override + public @NotNull ItemStack fromPrimitive(byte @NotNull [] arr, @NotNull PersistentDataAdapterContext persistentDataAdapterContext) { + ByteArrayInputStream bytes = new ByteArrayInputStream(arr); + try (BukkitObjectInputStream input = new BukkitObjectInputStream(bytes)) { + return (ItemStack) input.readObject(); + } catch (Exception e) { + e.printStackTrace(); + return new CustomItemStack(Material.STONE, "&cERROR"); + } + } + }; + + public IEStorageUnit(SlimefunItemStack item, int max, ItemStack[] recipe) { + super(BCGroups.STORAGES, item, RecipeType.ENHANCED_CRAFTING_TABLE, recipe); + this.max = max; + + addItemHandler(new BlockTicker() { + + @Override + public boolean isSynchronized() { + return true; + } + + @Override + public void tick(Block b, SlimefunItem item, Config data) { + IEStorageCache cache = caches.get(b.getLocation()); + if (cache != null) { + cache.tick(b); + } + } + + }, new BlockBreakHandler(false, false) { + + @Override + public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List drops) { + BlockMenu menu = BlockStorage.getInventory(e.getBlock()); + IEStorageCache cache = caches.remove(menu.getLocation()); + if (cache != null && !cache.isEmpty()) { + cache.destroy(e, drops); + } else { + drops.add(getItem().clone()); + } + menu.dropItems(menu.getLocation(), INPUT_SLOT, OUTPUT_SLOT); + } + + }, new BlockPlaceHandler(false) { + + @Override + public void onPlayerPlace(BlockPlaceEvent e) { + onPlace(e, e.getBlockPlaced()); + } + + }); + + new BlockMenuPreset(getId(), getItemName()) { + @Override + public void init() { + IEStorageUnit.this.setup(this); + } + + @Override + public boolean canOpen(@NotNull Block block, @NotNull Player player) { + return Slimefun.getProtectionManager().hasPermission(player, block, Interaction.INTERACT_BLOCK); + } + + @Override + public int[] getSlotsAccessedByItemTransport(ItemTransportFlow itemTransportFlow) { + return itemTransportFlow == ItemTransportFlow.WITHDRAW ? getInputSlots() : getOutputSlots(); + } + + @Override + public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) { + return flow == ItemTransportFlow.WITHDRAW ? getInputSlots(menu, item) : getOutputSlots(); + } + + @Override + public void newInstance(@NotNull BlockMenu menu, @NotNull Location l) { + caches.put(l, new IEStorageCache(IEStorageUnit.this, menu)); + } + }; + } + + static void transferToStack(@Nonnull ItemStack source, @Nonnull ItemStack target) { + Pair data = loadFromStack(source); + if (data != null) { + target.setItemMeta(saveToStack(target.getItemMeta(), data.getFirstValue(), + ItemUtils.getItemName(data.getFirstValue()), data.getSecondValue())); + } + } + + static ItemMeta saveToStack(ItemMeta meta, ItemStack displayItem, String displayName, int amount) { + if (meta.hasLore()) { + List lore = meta.getLore(); + lore.add(ChatColor.GOLD + "Stored: " + displayName + ChatColor.YELLOW + " x " + amount); + meta.setLore(lore); + } + meta.getPersistentDataContainer().set(ITEM_KEY, ITEM_STACK, displayItem); + meta.getPersistentDataContainer().set(AMOUNT_KEY, PersistentDataType.INTEGER, amount); + return meta; + } + + public ItemStack getDisplayingItem(Block b) { + List metadata = b.getMetadata("ie_item"); + if (metadata.isEmpty()) { + return BlockStorage.getInventory(b).getItemInSlot(DISPLAY_SLOT); + } else { + return (ItemStack) metadata.get(0).value(); + } + } + + @Nullable + private static Pair loadFromStack(ItemStack source) { + if (source.hasItemMeta()) { + PersistentDataContainer con = source.getItemMeta().getPersistentDataContainer(); + Integer amount = con.get(AMOUNT_KEY, PersistentDataType.INTEGER); + if (amount != null) { + ItemStack item = con.get(ITEM_KEY, ITEM_STACK); + if (item != null) { + return new Pair<>(item, amount); + } + } + } + return null; + } + + @Nonnull + @Override + public Collection getDrops() { + return Collections.emptyList(); + } + + private void onPlace(@Nonnull BlockPlaceEvent e, @Nonnull Block b) { + Pair data = loadFromStack(e.getItemInHand()); + if (data != null) { + IEStorageCache cache = this.caches.get(b.getLocation()); + cache.load(data.getFirstValue(), data.getFirstValue().getItemMeta()); + cache.amount(data.getSecondValue()); + b.setMetadata("ie_item", new FixedMetadataValue(BetterChests.INSTANCE, data.getFirstValue())); + } + } + + private void setup(@Nonnull BlockMenuPreset blockMenuPreset) { + blockMenuPreset.drawBackground(ChestMenuUtils.getInputSlotTexture(), new int[]{ + 0, 1, 2, 9, 11, 18, 19, 20 + }); + blockMenuPreset.drawBackground(ChestMenuUtils.getBackground(), new int[]{ + 3, 5, 12, 14, 21, 23 + }); + blockMenuPreset.drawBackground(ChestMenuUtils.getOutputSlotTexture(), new int[]{ + 6, 7, 8, 15, 17, 24, 25, 26 + }); + blockMenuPreset.addMenuClickHandler(DISPLAY_SLOT, ChestMenuUtils.getEmptyClickHandler()); + blockMenuPreset.addItem(INTERACT_SLOT, INTERACTION_ITEM); + blockMenuPreset.addItem(STATUS_SLOT, LOADING_ITEM); + } + + @Nonnull + private int[] getInputSlots(DirtyChestMenu dirtyChestMenu, ItemStack itemStack) { + IEStorageCache cache = this.caches.get(((BlockMenu) dirtyChestMenu).getLocation()); + if (cache != null && (cache.isEmpty() || cache.matches(itemStack))) { + cache.input(); + return new int[]{INPUT_SLOT}; + } else { + return new int[0]; + } + } + + @Override + public int[] getInputSlots() { + return new int[]{INPUT_SLOT}; + } + + @Override + public int[] getOutputSlots() { + return new int[]{OUTPUT_SLOT}; + } + + public void reloadCache(Block b) { + this.caches.get(b.getLocation()).reloadData(); + } + + @Nullable + public IEStorageCache getCache(Location location) { + return this.caches.get(location); + } + + @Override + public boolean canStack(@Nonnull ItemMeta sfItemMeta, @Nonnull ItemMeta itemMeta) { + return sfItemMeta.getPersistentDataContainer().equals(itemMeta.getPersistentDataContainer()); + } +} \ No newline at end of file diff --git a/src/main/java/me/mmmjjkx/betterChests/items/machines/ChestDisassembler.java b/src/main/java/me/mmmjjkx/betterChests/items/machines/ChestDisassembler.java index ea5cef5..d74174d 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/machines/ChestDisassembler.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/machines/ChestDisassembler.java @@ -16,7 +16,7 @@ public class ChestDisassembler extends AContainer implements RecipeDisplayItem { public ChestDisassembler(SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { - super(BCGroups.MAIN, item, recipeType, recipe); + super(BCGroups.TOOLS, item, recipeType, recipe); setProcessingSpeed(1); } @@ -28,7 +28,7 @@ protected void registerDefaultRecipes() { new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.OAK_PLANKS, 2) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_36.getItem().clone()}, @@ -56,56 +56,56 @@ protected void registerDefaultRecipes() { new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_INPUT_36.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_INPUT_45.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_INPUT_54.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_OUTPUT_27.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_OUTPUT_36.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_OUTPUT_45.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); registerRecipe(5, new ItemStack[]{BCItems.CHEST_OUTPUT_54.getItem().clone()}, new ItemStack[]{ new ItemStack(Material.CHEST, 1), new ItemStack(Material.HOPPER, 1) - }); + }); } @Override diff --git a/src/main/java/me/mmmjjkx/betterChests/items/tools/ChestColorer.java b/src/main/java/me/mmmjjkx/betterChests/items/tools/ChestColorer.java index 92dd4b8..112eef0 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/tools/ChestColorer.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/tools/ChestColorer.java @@ -33,7 +33,7 @@ public class ChestColorer extends SimpleSlimefunItem implements private static final NamespacedKey COLOR_KEY = new NamespacedKey(BetterChests.INSTANCE, "color"); public ChestColorer(SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { - super(BCGroups.MAIN, item, recipeType, recipe); + super(BCGroups.TOOLS, item, recipeType, recipe); } @Override diff --git a/src/main/java/me/mmmjjkx/betterChests/items/tools/LocationRecorder.java b/src/main/java/me/mmmjjkx/betterChests/items/tools/LocationRecorder.java index 848d651..78ad669 100644 --- a/src/main/java/me/mmmjjkx/betterChests/items/tools/LocationRecorder.java +++ b/src/main/java/me/mmmjjkx/betterChests/items/tools/LocationRecorder.java @@ -36,7 +36,7 @@ public class LocationRecorder extends SimpleSlimefunItem impleme private static final NamespacedKey Z = new NamespacedKey(BetterChests.INSTANCE, "pos_z"); public LocationRecorder(SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { - super(BCGroups.MAIN, item, recipeType, recipe); + super(BCGroups.TOOLS, item, recipeType, recipe); } @Override diff --git a/src/main/java/me/mmmjjkx/betterChests/items/tools/MultiLocationRecorder.java b/src/main/java/me/mmmjjkx/betterChests/items/tools/MultiLocationRecorder.java new file mode 100644 index 0000000..becfeb8 --- /dev/null +++ b/src/main/java/me/mmmjjkx/betterChests/items/tools/MultiLocationRecorder.java @@ -0,0 +1,30 @@ +package me.mmmjjkx.betterChests.items.tools; + +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; +import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable; +import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler; +import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; +import me.mmmjjkx.betterChests.BCGroups; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class MultiLocationRecorder extends SimpleSlimefunItem implements NotPlaceable { + public MultiLocationRecorder(SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(BCGroups.TOOLS, item, recipeType, recipe); + } + + @Override + public @NotNull ItemUseHandler getItemHandler() { + return e -> { + Player p = e.getPlayer(); + boolean gui = !p.isSneaking(); + if (gui) { + // TODO: Implement GUI + } else { + // TODO: Implement recording + } + }; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f6f6f70..9ea9e36 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: BetterChests version: 'Dev - ?' main: me.mmmjjkx.betterChests.BetterChests -api-version: '1.18' +api-version: '1.19' depend: ["Slimefun"] author: "mmmjjkx" \ No newline at end of file