Skip to content

Commit

Permalink
Add the option to break leaves instantly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Dec 20, 2019
1 parent 6cb053a commit 66797de
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## [1.15.1-2.0.1] - 2019-12-20
- Add an option in the config to instantly break leaves (defaults to false).

## [1.15.1-2.0.0] - 2019-12-17
- Port to 1.15.1
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Several options are available in the config file:
- 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).
2 changes: 1 addition & 1 deletion changes.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Port to 1.15.1
- Add an option in the config to instantly break leaves (defaults to false).
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ changelogUrl = https://github.com/RakSrinaNa/FallingTree/blob/1.15.1/CHANGELOG.m

mc_version = 1.15.1

forge_version = 1.15.1-30.0.0
forge_version = 1.15.1-30.0.14
mcp_channel = snapshot
mcp_mappings = 20191217-1.14.3
mcp_mappings = 20191220-1.14.3

curseforge_project_id=349559

Expand Down
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.0.0";
public static final String VERSION = "2.0.1";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public FallingTree(){
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/fr/raksrinana/fallingtree/ForgeEventSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import fr.raksrinana.fallingtree.config.Config;
import fr.raksrinana.fallingtree.tree.TreeHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IWorld;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import javax.annotation.Nonnull;
import java.util.Random;

@Mod.EventBusSubscriber(modid = FallingTree.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public final class ForgeEventSubscriber{
Expand Down Expand Up @@ -39,4 +46,21 @@ private static boolean isPlayerInRightState(PlayerEntity player){
}
return TreeHandler.canPlayerBreakTree(player);
}

@SubscribeEvent
public static void onNeighborNotifyEvent(BlockEvent.NeighborNotifyEvent event){
if(Config.COMMON.breakLeaves.get() && !event.getWorld().isRemote()){
BlockState state = event.getState();
Block block = state.getBlock();
BlockPos pos = event.getPos();
if(block.isIn(BlockTags.LEAVES)){
if(state.ticksRandomly()){
IWorld world = event.getWorld();
if(world instanceof ServerWorld){
block.func_225542_b_(state, (ServerWorld) world, pos, new Random());
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CommonConfig{
public final ForgeConfigSpec.BooleanValue ignoreDurabilityLoss;
public final ForgeConfigSpec.BooleanValue preserveTools;
public final ForgeConfigSpec.BooleanValue reverseSneaking;
public final ForgeConfigSpec.BooleanValue breakLeaves;
public final ForgeConfigSpec.IntValue maxTreeSize;


Expand All @@ -32,6 +33,7 @@ public CommonConfig(ForgeConfigSpec.Builder builder){
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);
reverseSneaking = builder.comment("When set to true, a tree will only be chopped down if the player is sneaking").define("reverse_sneaking", false);
breakLeaves = builder.comment("When set to true, leaves will be broken instantly").define("break_leaves", false);
}

public Stream<Block> getWhitelistedLogs(){
Expand Down
5 changes: 3 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"homepage": "https://github.com/RakSrinaNa/FallingTree",
"changelog": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.1/CHANGELOG.md",
"1.15.1": {
"2.0.1": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.1/CHANGELOG.md",
"2.0.0": "https://github.com/RakSrinaNa/FallingTree/blob/1.15.1/CHANGELOG.md"
},
"promos": {
"1.15.1-latest": "2.0.0",
"1.15.1-recommended": "2.0.0"
"1.15.1-latest": "2.0.1",
"1.15.1-recommended": "2.0.1"
}
}

0 comments on commit 66797de

Please sign in to comment.