more fixes

This commit is contained in:
okx-code
2024-11-02 15:13:10 +00:00
parent 1353ea1dbc
commit bf02c3d6bc
4 changed files with 48 additions and 39 deletions

View File

@@ -173,19 +173,19 @@ public class EditKitGui {
}
inventory.setSlot(getSlot(inventory, 39, Material.ORANGE_STAINED_GLASS_PANE, "Helmet",
() -> new ArmourSlotSelectionGui(dao, player, 39, kit, this, new ArrayList<>(MaterialTags.HELMETS.getValues())).open()),
() -> new ArmourSlotSelectionGui(dao, player, 39, kit, this, new ArrayList<>(MaterialTags.HELMETS.getValues()), List.of("meteoric_iron_helmet")).open()),
10);
inventory.setSlot(getSlot(inventory, 38, Material.ORANGE_STAINED_GLASS_PANE, "Chestplate",
() -> new ArmourSlotSelectionGui(dao, player, 38, kit, this, new ArrayList<>(MaterialTags.CHEST_EQUIPPABLE.getValues())).open()),
() -> new ArmourSlotSelectionGui(dao, player, 38, kit, this, new ArrayList<>(MaterialTags.CHEST_EQUIPPABLE.getValues()), List.of("meteoric_iron_chestplate")).open()),
11);
inventory.setSlot(getSlot(inventory, 37, Material.ORANGE_STAINED_GLASS_PANE, "Leggings",
() -> new ArmourSlotSelectionGui(dao, player, 37, kit, this, new ArrayList<>(MaterialTags.LEGGINGS.getValues())).open()),
() -> new ArmourSlotSelectionGui(dao, player, 37, kit, this, new ArrayList<>(MaterialTags.LEGGINGS.getValues()), List.of("meteoric_iron_leggings")).open()),
12);
inventory.setSlot(getSlot(inventory, 36, Material.ORANGE_STAINED_GLASS_PANE, "Boots",
() -> new ArmourSlotSelectionGui(dao, player, 36, kit, this, new ArrayList<>(MaterialTags.BOOTS.getValues())).open()),
() -> new ArmourSlotSelectionGui(dao, player, 36, kit, this, new ArrayList<>(MaterialTags.BOOTS.getValues()), List.of("meteoric_iron_boots")).open()),
13);
inventory.setSlot(getSlot(inventory, 40, Material.ORANGE_STAINED_GLASS_PANE, "Offhand",

View File

@@ -9,16 +9,19 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import vg.civcraft.mc.civmodcore.inventory.CustomItem;
import vg.civcraft.mc.civmodcore.inventory.gui.ClickableInventory;
import java.util.List;
public class ArmourSlotSelectionGui extends ItemSelectionGui {
private final List<Material> items;
private final List<String> custom;
public ArmourSlotSelectionGui(KitPvpDao dao, Player player, int slot, Kit kit, EditKitGui gui, List<Material> items) {
public ArmourSlotSelectionGui(KitPvpDao dao, Player player, int slot, Kit kit, EditKitGui gui, List<Material> items, List<String> custom) {
super(dao, "Armour", player, slot, kit, gui::open, gui);
this.items = items;
this.custom = custom;
}
@Override
@@ -29,8 +32,11 @@ public class ArmourSlotSelectionGui extends ItemSelectionGui {
none.setItemMeta(noneMeta);
inventory.setSlot(toClickable(none, null), 18);
for (int i = 0; i < Math.min(items.size(), 8); i++) {
for (int i = 0; i < items.size(); i++) {
inventory.setSlot(toClickable(new ItemStack(items.get(i))), 19 + i);
}
for (int i = 0; i < custom.size(); i++) {
inventory.setSlot(toClickable(CustomItem.getCustomItem(custom.get(i))), 19 + items.size() + i);
}
}
}

View File

@@ -24,6 +24,7 @@ import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import vg.civcraft.mc.civmodcore.inventory.CustomItem;
import vg.civcraft.mc.civmodcore.inventory.gui.Clickable;
import vg.civcraft.mc.civmodcore.inventory.gui.ClickableInventory;
@@ -41,44 +42,45 @@ public class EnchantmentGui extends ItemSelectionGui {
@Override
public void addItems(ClickableInventory inventory) {
ItemStack kitItem = kit.items()[this.slot].clone();
int slot = 0;
List<Enchantment> enchants = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).stream()
.sorted(Comparator.comparingInt(Enchantment::getMaxLevel).reversed())
.toList();
for (Enchantment enchantment : enchants) {
if (enchantment.canEnchantItem(kitItem)
&& !enchantment.isCursed()
&& enchantment != Enchantment.BANE_OF_ARTHROPODS
&& enchantment != Enchantment.SMITE
&& enchantment != Enchantment.MENDING) {
int pos = ENCHANT_START_SLOTS[slot++];
for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = book.getItemMeta();
meta.itemName(enchantment.displayName(level).color(NamedTextColor.GOLD));
book.setItemMeta(meta);
if (!CustomItem.isCustomItem(kitItem)) {
int slot = 0;
List<Enchantment> enchants = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).stream()
.sorted(Comparator.comparingInt(Enchantment::getMaxLevel).reversed())
.toList();
for (Enchantment enchantment : enchants) {
if (enchantment.canEnchantItem(kitItem)
&& !enchantment.isCursed()
&& enchantment != Enchantment.BANE_OF_ARTHROPODS
&& enchantment != Enchantment.SMITE
&& enchantment != Enchantment.MENDING) {
int pos = ENCHANT_START_SLOTS[slot++];
for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
ItemStack book = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = book.getItemMeta();
meta.itemName(enchantment.displayName(level).color(NamedTextColor.GOLD));
book.setItemMeta(meta);
ItemStack enchantedKitItem = kitItem.clone();
enchantedKitItem.addEnchantment(enchantment, level);
inventory.setSlot(toClickable(book, enchantedKitItem), pos++);
ItemStack enchantedKitItem = kitItem.clone();
enchantedKitItem.addEnchantment(enchantment, level);
inventory.setSlot(toClickable(book, enchantedKitItem), pos++);
}
}
}
if (!kitItem.getEnchantments().isEmpty()) {
ItemStack clearEnchants = new ItemStack(Material.BARRIER);
ItemMeta clearEnchantsMeta = clearEnchants.getItemMeta();
clearEnchantsMeta.itemName(Component.text("Clear enchants", NamedTextColor.GOLD));
clearEnchants.setItemMeta(clearEnchantsMeta);
ItemStack clearEnchantsItem = kitItem.clone();
ItemMeta clearEnchantsItemMeta = clearEnchantsItem.getItemMeta();
clearEnchantsItemMeta.removeEnchantments();
clearEnchantsItem.setItemMeta(clearEnchantsItemMeta);
inventory.setSlot(toClickable(clearEnchants, clearEnchantsItem), 51);
}
}
if (!kitItem.getEnchantments().isEmpty()) {
ItemStack clearEnchants = new ItemStack(Material.BARRIER);
ItemMeta clearEnchantsMeta = clearEnchants.getItemMeta();
clearEnchantsMeta.itemName(Component.text("Clear enchants", NamedTextColor.GOLD));
clearEnchants.setItemMeta(clearEnchantsMeta);
ItemStack clearEnchantsItem = kitItem.clone();
ItemMeta clearEnchantsItemMeta = clearEnchantsItem.getItemMeta();
clearEnchantsItemMeta.removeEnchantments();
clearEnchantsItem.setItemMeta(clearEnchantsItemMeta);
inventory.setSlot(toClickable(clearEnchants, clearEnchantsItem), 51);
}
// Damageable has a similar interface but for some reason it doesn't work
if (((CraftItemStack) kitItem).handle.has(DataComponents.MAX_DAMAGE)) {
if (kitItem.getItemMeta().isUnbreakable()) {
ItemStack breakable = new ItemStack(Material.CRACKED_STONE_BRICKS);

View File

@@ -76,5 +76,6 @@ public class WeaponsAndToolsSelectionGui extends ItemSelectionGui {
inventory.setSlot(toClickable(CustomItem.getCustomItem("meteoric_iron_sword")), 47);
inventory.setSlot(toClickable(CustomItem.getCustomItem("meteoric_iron_axe")), 48);
inventory.setSlot(toClickable(CustomItem.getCustomItem("meteoric_iron_pickaxe")), 49);
inventory.setSlot(toClickable(CustomItem.getCustomItem("backpack")), 50);
}
}