Skip to content
Open
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repositories {
maven { url "https://maven.enginehub.org/repo/" }
maven { url = 'https://repo.extendedclip.com/releases/' }
maven { url = "https://maven.zetaplugins.com/" }
maven { url "https://repo.nyon.dev/releases" }
}

def targetJavaVersion = 21
Expand Down Expand Up @@ -77,6 +78,7 @@ dependencies {
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.13'
compileOnly 'me.clip:placeholderapi:2.11.6'
compileOnly 'dev.aurelium:auraskills-api-bukkit:2.2.4'
compileOnly 'dev.nyon:magnetic:3.10.0-1.21.6+paper'
implementation "com.fasterxml.jackson.core:jackson-databind:2.16.1"

shadow "com.zetaplugins:zetacore:1.7.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zetaplugins.timberz.handler;

import com.zetaplugins.timberz.TimberZ;
import com.zetaplugins.timberz.service.magnetic.BreakingHelper;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -51,8 +52,7 @@ public void run() {
createBreakEffect(player, block, direction);

// Break the block naturally to drop items
Material blockType = block.getType();
block.breakNaturally(player.getInventory().getItemInMainHand());
BreakingHelper.breakBlock(block, player, player.getInventory().getItemInMainHand(), true);

// Random chance to spawn floating wood chips
if (random.nextInt(5) == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.zetaplugins.timberz.TimberZ;
import com.zetaplugins.timberz.service.MaterialTypeChecks;
import com.zetaplugins.timberz.service.PlayerStateService;
import com.zetaplugins.timberz.service.magnetic.BreakingHelper;
import com.zetaplugins.zetacore.annotations.AutoRegisterListener;
import org.bukkit.Material;
import org.bukkit.Sound;
Expand Down Expand Up @@ -42,7 +43,7 @@ public void onBlockBreak(BlockDamageEvent event) {
ItemStack tool = player.getInventory().getItemInMainHand();
if (tool.getType() == Material.AIR || !MaterialTypeChecks.isValidAxe(tool, plugin)) return;

brokenBlock.breakNaturally(tool);
BreakingHelper.breakBlock(brokenBlock, player, tool, true);
player.playSound(player.getLocation(), Sound.BLOCK_GRASS_BREAK, 1.0f, 1.0f);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.zetaplugins.timberz.TimberZ;
import com.zetaplugins.timberz.handler.SaplingReplanter;
import com.zetaplugins.timberz.handler.TreeAnimationHandler;
import com.zetaplugins.timberz.service.magnetic.BreakingHelper;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void fellTree(Player player, Block sourceBlock, Set<Block> treeBlocks, It

// Schedule leaf decay
if (!leafBlocks.isEmpty() && plugin.getConfig().getBoolean("instantLeafDecay")) {
scheduleLeafDecay(leafBlocks);
scheduleLeafDecay(leafBlocks, player, tool);
}

boolean shouldReplant = plugin.getConfig().getBoolean("replant");
Expand Down Expand Up @@ -149,7 +150,7 @@ private Set<Block> collectLeaves(Set<Block> treeBlocks, List<Material> leafType)
/**
* Schedules leaf decay with a natural-looking pattern
*/
private void scheduleLeafDecay(Set<Block> leafBlocks) {
private void scheduleLeafDecay(Set<Block> leafBlocks, Player player, ItemStack tool) {
List<Block> sortedLeaves = new ArrayList<>(leafBlocks);

// Sort leaves from bottom to top for more natural decay
Expand Down Expand Up @@ -178,8 +179,8 @@ public void run() {
Sound.BLOCK_GRASS_BREAK,
0.6f, pitch);

// Break the leaf naturally
leaf.breakNaturally();
// Break the leaf
BreakingHelper.breakBlock(leaf, player, tool, false);
}
}
}.runTaskLater(plugin, 5 + random.nextInt(40)); // Random delay between 5-45 ticks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.zetaplugins.timberz.service.magnetic;

import org.apache.commons.lang3.mutable.MutableInt;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

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

public class BreakingHelper {

public static void breakBlock(Block block, Player player, ItemStack tool, boolean shouldDamage) {
// If magnetic is not present, simply break naturally
if (!Bukkit.getPluginManager().isPluginEnabled("magnetic")) {
block.breakNaturally(tool);
return;
}

// Create magnetic drop event
ArrayList<ItemStack> drops = new ArrayList<>(block.getDrops(tool, player));
dev.nyon.magnetic.DropEvent dropEvent = new dev.nyon.magnetic.DropEvent(drops, new MutableInt(0), player, block.getLocation());
dropEvent.callEvent();

// Drop the remaining items that were not handled by magnetic
List<ItemStack> remainingItems = dropEvent.getItems();
World world = block.getWorld();
Location location = block.getLocation();
remainingItems.forEach(stack -> world.dropItem(location, stack));

// Play effects on break
world.playSound(location.toCenterLocation(), block.getBlockSoundGroup().getBreakSound(), 1f, 1f);

// Actually destroy block
block.setType(Material.AIR);

// Damage tool if tool is damageable
if (!tool.isEmpty() && tool.getType().getMaxDurability() > 0 && shouldDamage) tool.damage(1, player);
}
}
4 changes: 4 additions & 0 deletions src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ dependencies:
load: BEFORE
required: false
join-classpath: true
magnetic:
load: BEFORE
required: false
join-classpath: true

permissions:
timberz.admin:
Expand Down