Skip to content

Commit

Permalink
Add option to control damage multiplicand (closes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Apr 29, 2020
1 parent dc13f0e commit 8958d0c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.15.2-2.1.1] - 2020-04-29
- Add new configuration `tools > damage_multiplicand` to control how much damage the tools take (#9).

## [1.15.2-2.1.0] - 2020-03-08
- Refactor configuration by using categories thus making it a bit clearer than having everything stacked up at the same place. (/!\ You may have to redo your configuration if you changed values so back up the configuration before updating in order to copy values after)
- Break leaves without sound when using force breaking leaves (the option with the radius) to avoid breaking your ears (#7)
Expand Down
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ This mod will allow you to break a full tree by only breaking one log off of it.

![Demonstration of breaking a tree](https://github.com/RakSrinaNa/FallingTree/raw/1.14.4/assets/demo.gif)

Several options are available in the config file:
- logs_whitelisted: The mod automatically supports all bloks identified as logs. However if you want to manually add another kind of block (because it isn't identified as a log, or because you make trees out of obsidian) under the form `mod_id:block_id` (eg: `biomesoplenty:fir_log`).
- tools_whitelisted: The mod automatically supports all axes as tools. However if you can manually add more (because it isn't identified as an axe, or because you want to break your trees with a special tool) under the form `mod_id:item_id` (eg: `powder_power:axe_trilium`).
- logs_blacklisted: If you want to disallow some blocks to be broken all at once, you can do so here (if a block is both present in the whitelist & blacklist, the blacklist will win).
- tools_blacklisted: If you want to disallow the use of some tools, you can do so here (if an item is both present in the whitelist & blacklist, the blacklist will win).
- ignore_durability: If activated breaking down a tree won't damage your tool.
- max\_log\_count: The maximum number of log a tree can be mad of (if more the mod won't apply).
- preserve_tools: If this option is enabled your tool won't be broken by chopping down a big tree, it'll instead be left with 1 of durability.
- reverse_sneaking: If this option is enabled you'll need to sneak in order to break the whole tree.
- break_leaves: If this is set to true, leaves will despawn instantly when a tree is broken (even if not cut in one shot).
Several options can be configured:
- Blocks considered as logs
- Tools to cut trees
- Tools damage taken
- Max tree size
- Breaking leaves
3 changes: 1 addition & 2 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Refactor configuration by using categories thus making it a bit clearer than having everything stacked up at the same place. (/!\ You may have to redo your configuration if you changed values so back up the configuration before updating in order to copy values after)
- Break leaves without sound when using force breaking leaves (the option with the radius) to avoid breaking your ears (#7)
- Add new configuration `tools > damage_multiplicand` to control how much damage the tools take (#9).
2 changes: 1 addition & 1 deletion src/main/java/fr/raksrinana/fallingtree/FallingTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class FallingTree{
public static final String MOD_ID = "falling_tree";
public static final String MOD_NAME = "Falling Tree";
public static final String VERSION = "2.1.0";
public static final String VERSION = "2.1.1";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public FallingTree(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class ToolConfiguration{
private final ForgeConfigSpec.ConfigValue<List<? extends String>> blacklisted;
private final ForgeConfigSpec.BooleanValue ignoreDurabilityLoss;
private final ForgeConfigSpec.BooleanValue preserve;
private final ForgeConfigSpec.IntValue damageMultiplicand;

public ToolConfiguration(ForgeConfigSpec.Builder builder){
whitelisted = builder.comment("Additional list of tools (those marked with the axe tag will already be whitelisted) that can be used to chop down a tree").defineList("whitelisted", Lists.newArrayList(), Objects::nonNull);
blacklisted = builder.comment("List of tools that should not be considered as tools (this wins over the whitelist)").defineList("blacklisted", Lists.newArrayList(), 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);
preserve = 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", false);
damageMultiplicand = builder.comment("Defines the number of times the damage is applied to the tool (ie: if 1 then breaking 5 logs will give 5 damage; if set to 2, breaking 5 logs will give 10 damage). This only applies when the tree is cut when using the mod.").defineInRange("damage_multiplicand", 1, 1, Integer.MAX_VALUE);
}

public Stream<Item> getBlacklisted(){
Expand All @@ -35,4 +37,8 @@ public boolean isIgnoreDurabilityLoss(){
public boolean isPreserve(){
return this.preserve.get();
}

public int getDamageMultiplicand(){
return this.damageMultiplicand.get();
}
}
13 changes: 9 additions & 4 deletions src/main/java/fr/raksrinana/fallingtree/tree/TreeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.AxeItem;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -72,21 +73,25 @@ private static boolean isSameLog(@Nonnull IWorld world, @Nonnull BlockPos blockP

public static boolean destroy(@Nonnull Tree tree, @Nonnull PlayerEntity player, @Nonnull ItemStack tool){
final World world = tree.getWorld();
int toolUsesLeft = (!tool.isDamageable() || Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss()) ? Integer.MAX_VALUE : tool.getMaxDamage() - tool.getDamage();
final boolean noToolLoss = (!tool.isDamageable() || Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss());
final int damageMultiplicand = Config.COMMON.getToolsConfiguration().getDamageMultiplicand();
int toolUsesLeft = noToolLoss ? Integer.MAX_VALUE : ((tool.getMaxDamage() - tool.getDamage()) / damageMultiplicand);
if(Config.COMMON.getToolsConfiguration().isPreserve()){
toolUsesLeft--;
}
if(toolUsesLeft < 1){
return false;
}
final boolean isFullyBroken = Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss() || (tool.getMaxDamage() - tool.getDamage()) >= tree.getLogCount();
final boolean isTreeFullyBroken = noToolLoss || toolUsesLeft >= tree.getLogCount();
tree.getLogs().stream().limit(toolUsesLeft).forEachOrdered(logBlock -> {
final BlockState logState = world.getBlockState(logBlock);
if(!Config.COMMON.getToolsConfiguration().isIgnoreDurabilityLoss()){
tool.onBlockDestroyed(world, world.getBlockState(logBlock), logBlock, player);
tool.damageItem(damageMultiplicand, player, (entity) -> {});
}
player.addStat(Stats.ITEM_USED.get(logState.getBlock().asItem()));
world.destroyBlock(logBlock, true);
});
if(isFullyBroken){
if(isTreeFullyBroken){
final int radius = Config.COMMON.getTreesConfiguration().getLavesBreakingForceRadius();
if(radius > 0){
tree.getLogs().stream().max(Comparator.comparingInt(BlockPos::getY)).ifPresent(topLog -> {
Expand Down
5 changes: 3 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"homepage": "https://github.com/RakSrinaNa/FallingTree",
"changelog": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"1.15.2": {
"2.1.1": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.1.0": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.0.4": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.0.3": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md",
"2.0.2": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.2/CHANGELOG.md"
},
"promos": {
"1.15.2-latest": "2.1.0",
"1.15.2-recommended": "2.1.0"
"1.15.2-latest": "2.1.1",
"1.15.2-recommended": "2.1.1"
}
}

0 comments on commit 8958d0c

Please sign in to comment.