mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
added repairable
This commit is contained in:
@@ -7,6 +7,7 @@ import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.Reflections;
|
||||
import net.momirealms.craftengine.core.item.CustomItem;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
@@ -497,7 +498,19 @@ public class RecipeEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Item<ItemStack> newItem = plugin.itemManager().getCustomItem(left.id()).get().buildItem(ItemBuildContext.of(plugin.adapt(player), ContextHolder.EMPTY));
|
||||
Optional<CustomItem<ItemStack>> customItemOptional = plugin.itemManager().getCustomItem(left.id());
|
||||
if (!customItemOptional.isPresent()) {
|
||||
inventory.setResult(null);
|
||||
return;
|
||||
}
|
||||
|
||||
CustomItem<ItemStack> customItem = customItemOptional.get();
|
||||
if (!customItem.settings().canRepair()) {
|
||||
inventory.setResult(null);
|
||||
return;
|
||||
}
|
||||
|
||||
Item<ItemStack> newItem = customItem.buildItem(ItemBuildContext.of(plugin.adapt(player), ContextHolder.EMPTY));
|
||||
int remainingDurability = totalMaxDamage - totalDamage;
|
||||
int newItemDamage = Math.max(0, newItem.maxDamage().get() - remainingDurability);
|
||||
newItem.damage(newItemDamage);
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ItemSettings {
|
||||
Set<Key> tags = Set.of();
|
||||
@Nullable
|
||||
EquipmentGeneration equipment;
|
||||
boolean canRepair = true;
|
||||
|
||||
private ItemSettings() {}
|
||||
|
||||
@@ -39,6 +40,7 @@ public class ItemSettings {
|
||||
newSettings.fuelTime = settings.fuelTime;
|
||||
newSettings.tags = settings.tags;
|
||||
newSettings.equipment = settings.equipment;
|
||||
newSettings.canRepair = settings.canRepair;
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
@@ -54,6 +56,10 @@ public class ItemSettings {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public boolean canRepair() {
|
||||
return canRepair;
|
||||
}
|
||||
|
||||
public int fuelTime() {
|
||||
return fuelTime;
|
||||
}
|
||||
@@ -67,6 +73,11 @@ public class ItemSettings {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public ItemSettings canRepair(boolean canRepair) {
|
||||
this.canRepair = canRepair;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemSettings fuelTime(int fuelTime) {
|
||||
this.fuelTime = fuelTime;
|
||||
return this;
|
||||
@@ -98,6 +109,10 @@ public class ItemSettings {
|
||||
private static final Map<String, ItemSettings.Modifier.Factory> FACTORIES = new HashMap<>();
|
||||
|
||||
static {
|
||||
registerFactory("repairable", (value -> {
|
||||
boolean bool = (boolean) value;
|
||||
return settings -> settings.canRepair(bool);
|
||||
}));
|
||||
registerFactory("fuel-time", (value -> {
|
||||
int intValue = MiscUtils.getAsInt(value);
|
||||
return settings -> settings.fuelTime(intValue);
|
||||
|
||||
Reference in New Issue
Block a user