Skip to content
Draft
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
45 changes: 41 additions & 4 deletions src/main/java/fr/openmc/api/menulib/utils/MenuUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fr.openmc.api.menulib.Menu;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

Expand Down Expand Up @@ -99,9 +100,45 @@ public void run() {
*
* @return A list of integers representing the inventory item slots
*/
public static List<Integer> getInventoryItemSlots() {
return IntStream.rangeClosed(54, 89)
.boxed()
.toList();
public static List<Integer> getInventoryItemSlots(Menu menu) {

switch (menu.getInventorySize()) {
case SMALLEST -> {
return IntStream.rangeClosed(9, 44)
.boxed()
.toList();
}
case SMALL -> {
return IntStream.rangeClosed(18, 53)
.boxed()
.toList();
}

case NORMAL -> {
return IntStream.rangeClosed(27, 62)
.boxed()
.toList();
}

case LARGE -> {
return IntStream.rangeClosed(36, 71)
.boxed()
.toList();
}

case LARGER -> {
return IntStream.rangeClosed(45, 80)
.boxed()
.toList();
}

case LARGEST -> {
return IntStream.rangeClosed(54, 89)
.boxed()
.toList();
}

default -> throw new IllegalStateException("Unexpected value: " + menu.getInventorySize());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<ItemStack> getItems() {
public List<Integer> getTakableSlot() {
return Stream.concat(
CITY_MENU_ITEM_SLOTS.stream(),
MenuUtils.getInventoryItemSlots().stream()
MenuUtils.getInventoryItemSlots(this).stream()
).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ public void onClose(InventoryCloseEvent e) {

@Override
public List<Integer> getTakableSlot() {
return Stream.concat(MAILBOX_MENU_SLOTS.stream(), MenuUtils.getInventoryItemSlots().stream()).toList();
return Stream.concat(MAILBOX_MENU_SLOTS.stream(), MenuUtils.getInventoryItemSlots(this).stream()).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public static void init() {
registerItem(new AywenCap("omc_items:aywen_cap"));

/* Hammer */
registerItem(new Hammer("omc_items:iron_hammer", Material.IRON_PICKAXE, 1, 0));
registerItem(new Hammer("omc_items:diamond_hammer", Material.DIAMOND_PICKAXE, 1, 1));
registerItem(new Hammer("omc_items:netherite_hammer", Material.NETHERITE_PICKAXE, 1, 2));
registerItem(new Hammer("omc_items:iron_hammer", Material.IRON_PICKAXE, 1, 0, 1280)); // 20 stacks
registerItem(new Hammer("omc_items:diamond_hammer", Material.DIAMOND_PICKAXE, 1, 1, 3200)); // 50 stacks
registerItem(new Hammer("omc_items:netherite_hammer", Material.NETHERITE_PICKAXE, 1, 2, 12800)); // 200 stacks
}

public static void register(String name, CustomItem item) {
Expand Down
57 changes: 55 additions & 2 deletions src/main/java/fr/openmc/core/registry/items/contents/Hammer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
import fr.openmc.core.features.city.ProtectionsManager;
import fr.openmc.core.registry.items.CustomItem;
import fr.openmc.core.registry.items.options.BlockBreakableItem;
import fr.openmc.core.utils.messages.MessageType;
import fr.openmc.core.utils.messages.MessagesManager;
import fr.openmc.core.utils.messages.Prefix;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import lombok.Getter;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;

public class Hammer extends CustomItem implements BlockBreakableItem {

public static final float MAX_HARDNESS = 41.0f;
Expand All @@ -22,12 +32,16 @@ public class Hammer extends CustomItem implements BlockBreakableItem {
private final int radius;
@Getter
private final int depth;
private final int maxAywenite;

private static final NamespacedKey AYWENITE_HAMMER_KEY = new NamespacedKey("openmc", "aywenite_hammer_amount");

public Hammer(String namespacedId, Material vanillaMaterial, int radius, int depth) {
public Hammer(String namespacedId, Material vanillaMaterial, int radius, int depth, int maxAywenite) {
super(namespacedId);
this.vanillaMaterial = vanillaMaterial;
this.radius = radius;
this.depth = depth;
this.maxAywenite = maxAywenite;
}

private static BlockFace getTargetFace(Player player) {
Expand Down Expand Up @@ -99,12 +113,51 @@ public void onBlockBreak(Player player, BlockBreakEvent event) {
ItemStack tool = player.getInventory().getItemInMainHand();
if (tool.getType().isAir()) return;

int currentAywenite = getAywenite(tool);
if (currentAywenite < 1) {
MessagesManager.sendMessage(player, Component.text("§cVotre marteau est à court d'aywenite !"), Prefix.OPENMC, MessageType.ERROR, true);
event.setCancelled(true);
return;
}

Block origin = event.getBlock();
Material targetType = origin.getType();

if (!isBreakable(targetType)) return;

setAywenite(tool, currentAywenite - 1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Une utilisation du hammer = -1 aywenite? c'est un peu trop nerf la nn? fait -1 a une utilisation paire genre -1 a 0 2 4 6 8 10 ect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, j'suis pas forcement d'accord, car avec un hammer, par exemple avec le netherite tu casse en 3x3x3, pour 1 aywenite

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui mais pour l'hammer en fer bon 😂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apres je vois pas vraiment ce que tu veux dire ?
genre une utilisation = 0.5 d'aywenite use ?
si oui, c'est un peu trop relou a gerer
mais bon, l'aywenite n'est pas si rare que sa apres

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mais bon, l'aywenite n'est pas si rare que sa apres
Je suis d'acc mais faut qd meme doser, ptet demander aux joueurs de ce qu'ils en pensent (rylo ou louty par ex)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genre une utilisation = 0.5 d'aywenite use ?

en gros mais faut pas le coder comme ça mdr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est pas impossible ? Tu mets un compteur sur les pdc, blocks broken=0 par défaut tu fais une utilisation+1, dès que tu arrives à 2, tu mets a zéro et tu enlèves un d'aywenite?

j'avais mis une explication

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm


BlockFace face = getTargetFace(player).getOppositeFace();
breakArea(player, origin, face, tool, targetType);
}

public int getAywenite(ItemStack item) {
Comment thread
AxenoDev marked this conversation as resolved.
ItemMeta meta = item.getItemMeta();
if (meta == null) return 0;
return meta.getPersistentDataContainer().getOrDefault(AYWENITE_HAMMER_KEY, PersistentDataType.INTEGER, 0);
}

public void setAywenite(ItemStack item, int value) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si tu pourrais faire varier la durabilité de l'item en fonction du nombre d'aywenite dedans ça pourrait etre bien visuellement.
mais ça ferais que les hammers aient une durabilité infinie

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop, trop complexe, j'avais deja essaye

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fin en soit c'est meme pas que c'est trop complexe, c'est que c'est un peu impossible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est pas impossible ? Tu mets un compteur sur les pdc, blocks broken=0 par défaut tu fais une utilisation+1, dès que tu arrives à 2, tu mets a zéro et tu enlèves un d'aywenite?

Copy link
Copy Markdown
Member

@iambibi iambibi May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ou au pire du pire tu mets une map qui se reset chaque démarrage mais c'est moins propre

item.editMeta(meta -> {
meta.getPersistentDataContainer().set(AYWENITE_HAMMER_KEY, PersistentDataType.INTEGER, value);

List<Component> lore = meta.lore();
if (lore == null) {
lore = new ArrayList<>();
}

Component ayweniteLine = Component.text("§7Aywenite: §e" + value + "/" + maxAywenite)
.decoration(TextDecoration.ITALIC, false);

if (lore.size() <= 1) {
if (lore.isEmpty()) {
lore.add(Component.text("§8Marteau de minage zone"));
}
lore.add(ayweniteLine);
} else {
lore.set(1, ayweniteLine);
}

meta.lore(lore);
});
}
}
Loading