Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -260,7 +272,11 @@ void destroy(BlockBreakEvent e, List<ItemStack> 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));
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,7 +61,7 @@ quarry-options:
redstone: true
netherite: true
netherrack: true

# 设置高级铁砧的附魔等级上限
advanced-anvil-max-levels:
sharpness: 9
Expand Down