-
Notifications
You must be signed in to change notification settings - Fork 29
Permet de recharger les hammers en aywenite #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0a349d4
96ebb8e
b3c0f43
7002c0e
822e58a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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) { | ||
|
|
@@ -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); | ||
|
|
||
| BlockFace face = getTargetFace(player).getOppositeFace(); | ||
| breakArea(player, origin, face, tool, targetType); | ||
| } | ||
|
|
||
| public int getAywenite(ItemStack item) { | ||
|
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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nop, trop complexe, j'avais deja essaye
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 😂
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm