9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-26 10:29:20 +00:00

添加堆肥成功率

This commit is contained in:
XiaoMoMi
2025-06-14 04:44:01 +08:00
parent 52f9a7c9e7
commit 9199a1cd2c
2 changed files with 25 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.bukkit.item.listener;
import io.papermc.paper.event.block.CompostItemEvent;
import net.momirealms.craftengine.bukkit.api.event.CustomBlockInteractEvent;
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
@@ -428,4 +429,13 @@ public class ItemEventListener implements Listener {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onCompost(CompostItemEvent event) {
ItemStack itemToCompost = event.getItem();
Item<ItemStack> wrapped = this.plugin.itemManager().wrap(itemToCompost);
Optional<CustomItem<ItemStack>> optionalCustomItem = wrapped.getCustomItem();
if (optionalCustomItem.isEmpty()) return;
event.setWillRaiseLevel(RandomUtils.generateRandomFloat(0, 1) < optionalCustomItem.get().settings().compostProbability());
}
}

View File

@@ -37,6 +37,7 @@ public class ItemSettings {
Key craftRemainder = null;
List<DamageSource> invulnerable = List.of();
boolean canEnchant = true;
float compostProbability= 0.5f;
private ItemSettings() {}
@@ -77,6 +78,7 @@ public class ItemSettings {
newSettings.craftRemainder = settings.craftRemainder;
newSettings.invulnerable = settings.invulnerable;
newSettings.canEnchant = settings.canEnchant;
newSettings.compostProbability = settings.compostProbability;
return newSettings;
}
@@ -157,6 +159,10 @@ public class ItemSettings {
return invulnerable;
}
public float compostProbability() {
return compostProbability;
}
public ItemSettings repairItems(List<AnvilRepairItem> items) {
this.anvilRepairItems = items;
return this;
@@ -172,6 +178,11 @@ public class ItemSettings {
return this;
}
public ItemSettings compostProbability(float chance) {
this.compostProbability = chance;
return this;
}
public ItemSettings canRepair(boolean canRepair) {
this.canRepair = canRepair;
return this;
@@ -323,6 +334,10 @@ public class ItemSettings {
Map<String, Object> args = MiscUtils.castToMap(value, false);
return settings -> settings.helmet(new Helmet(SoundData.create(args.getOrDefault("equip-sound", "minecraft:intentionally_empty"), 1f, 1f)));
}));
registerFactory("compost-probability", (value -> {
float chance = ResourceConfigUtils.getAsFloat(value, "compost-probability");
return settings -> settings.compostProbability(chance);
}));
registerFactory("dyeable", (value -> {
boolean bool = (boolean) value;
return settings -> settings.dyeable(bool);