-
Notifications
You must be signed in to change notification settings - Fork 31
Ajout du hammer et de la builder wand #649
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
Open
AxenoDev
wants to merge
10
commits into
ServerOpenMC:master
Choose a base branch
from
AxenoDev:feat/hammer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4fec146
feat: add abstract hammer class and specific hammer implementations
AxenoDev 0f1f491
removing unused class
AxenoDev b2db6f1
feat: enhance AbstractHammer functionality with optimized block proce…
AxenoDev 0223f26
Merge branch 'master' into feat/hammer
AxenoDev 2e48529
Merge branch 'master' into feat/hammer
AxenoDev 8b97ba5
Merge branch 'master' into feat/hammer
AxenoDev d0c92cd
feat: refactor hammer classes and update item registry initialization
AxenoDev 8b2da35
feat: reorganize Hammer class methods and restore block breaking func…
AxenoDev 9e408d3
feat: improve block interaction handling and streamline method implem…
AxenoDev 37db7f5
feat: update Hammer class package structure and modify constructor vi…
AxenoDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/main/java/fr/openmc/core/items/usable/tools/Hammer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package fr.openmc.core.items.usable.tools; | ||
|
|
||
| import fr.openmc.core.features.city.ProtectionsManager; | ||
| import fr.openmc.core.items.usable.CustomUsableItem; | ||
| 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.util.RayTraceResult; | ||
| import org.bukkit.util.Vector; | ||
|
|
||
| public class Hammer extends CustomUsableItem { | ||
|
|
||
| private static final float MAX_HARDNESS = 41.0f; | ||
|
|
||
| private final Material vanillaMaterial; | ||
| private final int radius; | ||
| private final int depth; | ||
|
|
||
| public Hammer(String namespacedId, Material vanillaMaterial, int radius, int depth) { | ||
| super(namespacedId); | ||
| this.vanillaMaterial = vanillaMaterial; | ||
| this.radius = radius; | ||
| this.depth = depth; | ||
| } | ||
|
|
||
| private static BlockFace getTargetFace(Player player) { | ||
| Location eye = player.getEyeLocation(); | ||
| RayTraceResult result = eye.getWorld().rayTraceBlocks(eye, eye.getDirection(), 10, FluidCollisionMode.NEVER); | ||
|
|
||
| return result != null && result.getHitBlockFace() != null ? result.getHitBlockFace() : BlockFace.SELF; | ||
| } | ||
|
|
||
| private static Vector rotateOffset(int x, int y, int z, BlockFace face) { | ||
| return switch (face) { | ||
| case NORTH, SOUTH -> new Vector(x, y, z); | ||
| case EAST, WEST -> new Vector(z, y, x); | ||
| case UP, DOWN -> new Vector(x, z, y); | ||
| default -> new Vector(0, 0, 0); | ||
| }; | ||
| } | ||
|
|
||
| private void breakArea(Player player, Block origin, BlockFace face, ItemStack tool, Material targetType) { | ||
| World world = origin.getWorld(); | ||
| int ox = origin.getX(); | ||
| int oy = origin.getY(); | ||
| int oz = origin.getZ(); | ||
|
|
||
| for (int dx = -radius; dx <= radius; dx++) { | ||
| for (int dy = -radius; dy <= radius; dy++) { | ||
| for (int dz = -depth; dz <= depth; dz++) { | ||
|
|
||
| if (dx == 0 && dy == 0 && dz == 0) continue; | ||
|
|
||
| Vector offset = rotateOffset(dx, dy, dz, face); | ||
| breakBlock(world, player, tool, ox + offset.getBlockX(), oy + offset.getBlockY(), oz + offset.getBlockZ(), targetType); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void breakBlock(World world, Player player, ItemStack tool, int x, int y, int z, Material targetType) { | ||
| Block block = world.getBlockAt(x, y, z); | ||
|
|
||
| if (block.getType() != targetType) return; | ||
| if (!isBreakable(block.getType())) return; | ||
| if (!ProtectionsManager.canInteract(player, block.getLocation())) return; | ||
|
|
||
| block.breakNaturally(tool); | ||
| } | ||
|
|
||
| private boolean isBreakable(Material material) { | ||
| return !material.isAir() && material.getHardness() <= MAX_HARDNESS; | ||
| } | ||
|
|
||
| @Override | ||
| public ItemStack getVanilla() { | ||
| return ItemStack.of(vanillaMaterial); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBlockBreak(Player player, BlockBreakEvent event) { | ||
| if (player.getGameMode() != GameMode.SURVIVAL) return; | ||
|
|
||
| ItemStack tool = player.getInventory().getItemInMainHand(); | ||
| if (tool.getType().isAir()) return; | ||
|
|
||
| Block origin = event.getBlock(); | ||
| Material targetType = origin.getType(); | ||
|
|
||
| if (!isBreakable(targetType)) return; | ||
|
|
||
| BlockFace face = getTargetFace(player).getOppositeFace(); | ||
| breakArea(player, origin, face, tool, targetType); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/main/java/fr/openmc/core/listeners/BlockBreakListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package fr.openmc.core.listeners; | ||
|
|
||
| import fr.openmc.core.features.city.ProtectionsManager; | ||
| import fr.openmc.core.items.usable.CustomUsableItem; | ||
| import fr.openmc.core.items.usable.CustomUsableItemRegistry; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.block.BlockBreakEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| public class BlockBreakListener implements Listener { | ||
|
|
||
| @EventHandler | ||
| public void onBlockBreak(BlockBreakEvent event) { | ||
| Player player = event.getPlayer(); | ||
| if (event.isCancelled()) return; | ||
| if (event.getBlock() == null) return; | ||
| ProtectionsManager.verify(player, event, event.getBlock().getLocation()); | ||
|
|
||
| ItemStack itemInHand = player.getInventory().getItemInMainHand(); | ||
| CustomUsableItem usableItem = CustomUsableItemRegistry.getByItemStack(itemInHand); | ||
|
|
||
| if (usableItem != null) usableItem.handleBlockBreak(player, event); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
a verifier le comportement de la MeteoWand.
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 a dire ? J'ai rien modifie dans la methode ?
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.
Non mais juste pour être sûr (fin théoriquement lorsque tu testes ta feature, tu testes les choses qui ont les même fonctionnalités genre un PlayerClickEvent (jsp comment il s'appelle mais ta compris)
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.
t'es good?