Skip to content

Commit

Permalink
Fix #1, add option to preserve tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Oct 27, 2019
1 parent 0ab6f0a commit 678d6a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ public static void onBlockBreakEvent(@Nonnull BlockEvent.BreakEvent event){
TreeHandler.getTree(event.getWorld(), event.getPos()).ifPresent(tree -> {
if(Config.SERVER.maxTreeSize.get() >= tree.getLogCount()){
ItemStack tool = event.getPlayer().getHeldItem(Hand.MAIN_HAND);
if(Config.SERVER.ignoreDurabilityLoss.get() || !tool.isDamageable() || tree.getLogCount() <= (tool.getMaxDamage() - tool.getDamage())){
TreeHandler.destroy(tree, event.getPlayer(), tool);
int toolUsesLeft = tool.getMaxDamage() - tool.getDamage();
if(Config.SERVER.ignoreDurabilityLoss.get() || !tool.isDamageable() || (Config.SERVER.preserveTools.get() && tree.getLogCount() <= toolUsesLeft)){
if(Config.SERVER.ignoreDurabilityLoss.get() || !Config.SERVER.preserveTools.get() || tree.getLogCount() < toolUsesLeft){
TreeHandler.destroy(tree, event.getPlayer(), tool);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ServerConfig{
public final ForgeConfigSpec.ConfigValue<List<? extends String>> whitelistedLogs;
public final ForgeConfigSpec.ConfigValue<List<? extends String>> whitelistedTools;
public final ForgeConfigSpec.BooleanValue ignoreDurabilityLoss;
public final ForgeConfigSpec.BooleanValue preserveTools;
public final ForgeConfigSpec.IntValue maxTreeSize;


Expand All @@ -23,7 +24,8 @@ public ServerConfig(ForgeConfigSpec.Builder builder){
whitelistedLogs = builder.comment("List of blocks considered as logs and will be destroyed all at once").defineList("logs_whitelisted", Lists.newArrayList("minecraft:acacia_log", "minecraft:birch_log", "minecraft:dark_oak_log", "minecraft:jungle_log", "minecraft:oak_log", "minecraft:spruce_log"), Objects::nonNull);
whitelistedTools = builder.comment("List of tools that can be used to chop down a tree").defineList("tools_whitelisted", Lists.newArrayList("minecraft:wooden_axe", "minecraft:golden_axe", "minecraft:stone_axe", "minecraft:iron_axe", "minecraft:diamond_axe"), Objects::nonNull);
ignoreDurabilityLoss = builder.comment("Ignore the durability loss of breaking all the logs. If set to true, no harm will be done to the tool").define("ignore_durability", false);
maxTreeSize = builder.comment("The maximum size of a tree. If there's more logs than this value the tree won't be cut.").defineInRange("max_log_count", 1000, 1, Integer.MAX_VALUE);
maxTreeSize = builder.comment("The maximum size of a tree. If there's more logs than this value the tree won't be cut.").defineInRange("max_log_count", 100, 1, Integer.MAX_VALUE);
preserveTools = builder.comment("When set to true, when a tree is broken and the tool is about to break we will just break one block and not the whole tree.").define("preserve-tools", false);
}

public Stream<Block> getWhitelistedLogs(){
Expand Down

0 comments on commit 678d6a8

Please sign in to comment.