diff --git a/src/main/java/io/github/mooy1/infinityexpansion/items/quarries/Quarries.java b/src/main/java/io/github/mooy1/infinityexpansion/items/quarries/Quarries.java index b299aed6..17cc34ca 100644 --- a/src/main/java/io/github/mooy1/infinityexpansion/items/quarries/Quarries.java +++ b/src/main/java/io/github/mooy1/infinityexpansion/items/quarries/Quarries.java @@ -76,6 +76,9 @@ public final class Quarries { private static double getOscillatorChance(String type) { return InfinityExpansion.config().getDouble("quarry-options.oscillators." + type, 0, 1); } + private static double getCustomOscillatorChance(String type){ + return InfinityExpansion.config().getDouble("quarry-options.extra-oscillators." + type, 0, 1); + } public static void setup(InfinityExpansion plugin) { ConfigurationSection section = plugin.getConfig().getConfigurationSection("quarry-options.resources"); @@ -103,24 +106,27 @@ public static void setup(InfinityExpansion plugin) { } if (section.getBoolean("redstone")) { - new Oscillator(REDSTONE_OSCILLATOR, REDSTONE_CHANCE).register(plugin); outputs.add(Material.REDSTONE); } + new Oscillator(REDSTONE_OSCILLATOR, REDSTONE_CHANCE).register(plugin); + if (section.getBoolean("lapis")) { - new Oscillator(LAPIS_OSCILLATOR, LAPIS_CHANCE).register(plugin); outputs.add(Material.LAPIS_LAZULI); } + new Oscillator(LAPIS_OSCILLATOR, LAPIS_CHANCE).register(plugin); if (section.getBoolean("emerald")) { - new Oscillator(EMERALD_OSCILLATOR, EMERALD_CHANCE).register(plugin); outputs.add(Material.EMERALD); } + new Oscillator(EMERALD_OSCILLATOR, EMERALD_CHANCE).register(plugin); + if (section.getBoolean("diamond")) { - new Oscillator(DIAMOND_OSCILLATOR, DIAMOND_CHANCE).register(plugin); outputs.add(Material.DIAMOND); } + new Oscillator(DIAMOND_OSCILLATOR, DIAMOND_CHANCE).register(plugin); + new Quarry(Groups.ADVANCED_MACHINES, BASIC_QUARRY, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { Materials.MAGSTEEL_PLATE, SlimefunItems.CARBONADO_EDGED_CAPACITOR, Materials.MAGSTEEL_PLATE, @@ -129,10 +135,10 @@ public static void setup(InfinityExpansion plugin) { }, 1, 6, outputs.toArray(new Material[0])).energyPerTick(300).register(plugin); if (section.getBoolean("quartz")) { - new Oscillator(QUARTZ_OSCILLATOR, QUARTZ_CHANCE).register(plugin); - outputs.add(Material.QUARTZ); } + new Oscillator(QUARTZ_OSCILLATOR, QUARTZ_CHANCE).register(plugin); + if (section.getBoolean("netherite")) { outputs.add(Material.NETHERITE_INGOT); @@ -171,6 +177,20 @@ public static void setup(InfinityExpansion plugin) { Materials.VOID_INGOT, null, Materials.INFINITE_INGOT, Materials.INFINITE_INGOT, null, Materials.VOID_INGOT, Materials.VOID_INGOT, null, Materials.INFINITE_INGOT, Materials.INFINITE_INGOT, null, Materials.VOID_INGOT }, 64, 1, outputs.toArray(new Material[0])).energyPerTick(36000).register(plugin); + + + var extraOscillators = InfinityExpansion.config() .getConfigurationSection("quarry-options.extra-oscillators"); + if(extraOscillators != null) { + for (String material: extraOscillators.getKeys(false)) { + Material extraMaterial = Material.getMaterial(material); + if(extraMaterial != null) { + new Oscillator(Oscillator.create(extraMaterial, getCustomOscillatorChance(material)), getCustomOscillatorChance(material)) + .register(plugin); + } + } + } + + } } diff --git a/src/main/java/io/github/mooy1/infinityexpansion/items/storage/StorageCache.java b/src/main/java/io/github/mooy1/infinityexpansion/items/storage/StorageCache.java index 42feae11..02cbe1c7 100644 --- a/src/main/java/io/github/mooy1/infinityexpansion/items/storage/StorageCache.java +++ b/src/main/java/io/github/mooy1/infinityexpansion/items/storage/StorageCache.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import java.util.regex.Pattern; import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData; @@ -118,6 +119,9 @@ public final class StorageCache { // load the item in menu load(display, copy); } + }else{ + //if display item lost, reset amount record + setEmpty(); } } @@ -174,6 +178,14 @@ else if (!isEmpty()) { updateStatus(); } + private ItemStack generateRandomDisplayItem(ItemStack input){ + ItemMeta meta = input.getItemMeta(); + meta.getPersistentDataContainer().set(DISPLAY_KEY, PersistentDataType.INTEGER, ThreadLocalRandom.current().nextInt()); + var display = new ItemStack(input.getType()); + display.setItemMeta(meta); + return display; + } + private void setDisplayName(String name) { this.displayName = name; @@ -260,7 +272,11 @@ void destroy(BlockBreakEvent e, List drops) { ItemStack drop = this.storageUnit.getItem().clone(); ItemStack displayItem = this.menu.getItemInSlot(DISPLAY_SLOT); - if (displayItem == null || displayItem.getType().isAir()) { + if( displayItem == null || displayItem.getType().isAir()){ + displayItem = new ItemStack(this.material).clone(); + displayItem.setItemMeta(this.meta); + } + if ( displayItem.getType().isAir()) { e.getPlayer().sendMessage(ChatColor.RED + "物品丢失,无法恢复"); } else { drop.setItemMeta(StorageUnit.saveToStack(drop.getItemMeta(), this.menu.getItemInSlot(DISPLAY_SLOT), this.displayName, this.amount)); @@ -280,7 +296,7 @@ void reloadData() { } void load(ItemStack stored, ItemMeta copy) { - this.menu.replaceExistingItem(DISPLAY_SLOT, stored); + this.menu.replaceExistingItem(DISPLAY_SLOT, generateRandomDisplayItem(stored)); // remove the display key from copy copy.getPersistentDataContainer().remove(DISPLAY_KEY); @@ -404,6 +420,11 @@ private void updateStatus() { lore.add(ChatColor.GRAY + "(点击切换)"); meta.setLore(lore); }), false); + if(this.isEmpty()){ + this.menu.replaceExistingItem(DISPLAY_SLOT, EMPTY_ITEM); + }else { + this.menu.replaceExistingItem(DISPLAY_SLOT, generateRandomDisplayItem(createItem(1))); + } } private static boolean checkWallSign(Block sign, Block block) { @@ -417,12 +438,12 @@ public void setStored(ItemStack 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); +// 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); + this.menu.replaceExistingItem(DISPLAY_SLOT, generateRandomDisplayItem(input)); } public void setEmpty() { diff --git a/src/main/java/io/github/mooy1/infinityexpansion/utils/Util.java b/src/main/java/io/github/mooy1/infinityexpansion/utils/Util.java index f9488475..c90e1be0 100644 --- a/src/main/java/io/github/mooy1/infinityexpansion/utils/Util.java +++ b/src/main/java/io/github/mooy1/infinityexpansion/utils/Util.java @@ -15,6 +15,7 @@ import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; @@ -25,9 +26,11 @@ import io.github.mooy1.infinityexpansion.InfinityExpansion; +import org.bukkit.persistence.PersistentDataType; + @UtilityClass public final class Util { - + static final NamespacedKey DISPLAY_KEY = InfinityExpansion.createKey("display-only"); @Nonnull public static ItemStack getDisplayItem(@Nonnull ItemStack output) { ItemMeta meta = output.getItemMeta(); @@ -42,6 +45,8 @@ public static ItemStack getDisplayItem(@Nonnull ItemStack output) { lore.add(ChatColor.GREEN + "-------------------"); lore.add(ChatColor.GREEN + "\u21E8 点击合成"); lore.add(ChatColor.GREEN + "-------------------"); + meta.setLore(lore); + meta.getPersistentDataContainer().set(DISPLAY_KEY, PersistentDataType.BYTE,(byte)1); output.setItemMeta(meta); return output; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 123ab305..d38c4614 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -35,7 +35,10 @@ quarry-options: redstone: .5 quartz: .5 emerald: .5 - + #额外生产加速器 + extra-oscillators: + #以材料大写id为key,不可以与上面的相同 + SAMPLE_MATERIAL: .5 # 每隔多少粘液刻输出产物 # # 在没有更改 Slimefun 设置的情况下,1 粘液刻 = 0.5 秒 ticks-per-output: 10 @@ -58,7 +61,7 @@ quarry-options: redstone: true netherite: true netherrack: true - + # 设置高级铁砧的附魔等级上限 advanced-anvil-max-levels: sharpness: 9