diff --git a/build.gradle b/build.gradle index fdbbe734e7..d691fb9c0d 100644 --- a/build.gradle +++ b/build.gradle @@ -170,6 +170,10 @@ dependencies { //runtimeOnly("cc.tweaked:cc-tweaked-${cc_tweaked_minecraft_version}-forge:${cc_tweaked_version}") } + if (dynamic_trees_enable.toBoolean()) { + compileOnly("com.dtteam.dynamictrees:dynamictrees-neoforge-${dynamic_trees_minecraft_version}:${dynamic_trees_version}") + } + runtimeOnly("dev.architectury:architectury-neoforge:13.0.8") implementation("dev.ftb.mods:ftb-chunks-neoforge:2101.1.1") implementation("dev.ftb.mods:ftb-teams-neoforge:2101.1.0") diff --git a/gradle.properties b/gradle.properties index 5c30644d5d..e4988abcb1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,6 +34,10 @@ cc_tweaked_enable = true cc_tweaked_minecraft_version = 1.21.1 cc_tweaked_version = 1.114.2 +dynamic_trees_enable = true +dynamic_trees_minecraft_version = 1.21.1 +dynamic_trees_version = 1.5.0-BETA07 + # mod options mod_id = create mod_name = Create diff --git a/src/main/java/com/simibubi/create/compat/dynamictrees/DynamicTree.java b/src/main/java/com/simibubi/create/compat/dynamictrees/DynamicTree.java index b5743bdae5..e515e4a349 100644 --- a/src/main/java/com/simibubi/create/compat/dynamictrees/DynamicTree.java +++ b/src/main/java/com/simibubi/create/compat/dynamictrees/DynamicTree.java @@ -4,13 +4,19 @@ import javax.annotation.Nullable; +import com.dtteam.dynamictrees.tree.TreeHelper; +import com.dtteam.dynamictrees.block.branch.BranchBlock; +import com.dtteam.dynamictrees.block.branch.TrunkShellBlock; +import com.dtteam.dynamictrees.api.network.BranchDestructionData; import com.simibubi.create.foundation.utility.AbstractBlockBreakQueue; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; public class DynamicTree extends AbstractBlockBreakQueue { @@ -21,47 +27,46 @@ public DynamicTree(BlockPos startCutPos) { } public static boolean isDynamicBranch(Block block) { - //return TreeHelper.isBranch(block) || block instanceof TrunkShellBlock; - return false; + return TreeHelper.isBranch(block) || block instanceof TrunkShellBlock; } @Override public void destroyBlocks(Level world, ItemStack toDamage, @Nullable Player playerEntity, BiConsumer drop) { -// BranchBlock start = TreeHelper.getBranch(world.getBlockState(startCutPos)); -// if (start == null) //if start is null, it was not a branch -// start = setBranchToShellMuse(world, world.getBlockState(startCutPos)); //we check for a trunk shell instead -// -// if (start == null) //if it is null again, it was neither a branch nor a trunk shell and thus we return -// return; -// -// // Play and render block break sound and particles -// world.levelEvent(null, 2001, startCutPos, Block.getId(world.getBlockState(startCutPos))); -// -// // Actually breaks the tree -// BranchDestructionData data = start.destroyBranchFromNode(world, startCutPos, Direction.DOWN, false, playerEntity); -// -// // Feed all the tree drops to drop bi-consumer -// data.leavesDrops.forEach(stackPos -> drop.accept(stackPos.pos.offset(startCutPos), stackPos.stack)); -// start.getFamily().getCommonSpecies().getBranchesDrops(world, data.woodVolume).forEach(stack -> drop.accept(startCutPos, stack)); + BranchBlock start = TreeHelper.getBranch(world.getBlockState(startCutPos)); + if (start == null) //if start is null, it was not a branch + start = setBranchToShellMuse(world, world.getBlockState(startCutPos)); //we check for a trunk shell instead + + if (start == null) //if it is null again, it was neither a branch nor a trunk shell and thus we return + return; + + // Play and render block break sound and particles + world.levelEvent(null, 2001, startCutPos, Block.getId(world.getBlockState(startCutPos))); + + // Actually breaks the tree + BranchDestructionData data = start.destroyBranchFromNode(world, startCutPos, Direction.DOWN, false, playerEntity); + + // Feed all the tree drops to drop bi-consumer + data.leavesDrops.forEach(stackPos -> drop.accept(stackPos.pos.offset(startCutPos), stackPos.stack)); + start.getFamily().getCommonSpecies().getBranchesDrops(world, data.woodVolume).forEach(stack -> drop.accept(startCutPos, stack)); } -// private BranchBlock setBranchToShellMuse(Level world, BlockState state) { -// -// Block block = state.getBlock(); -// if (block instanceof TrunkShellBlock){ -// TrunkShellBlock.ShellMuse muse = ((TrunkShellBlock)block).getMuse(world, startCutPos); -// if (muse != null){ -// startCutPos = muse.pos; //the cut pos is moved to the center of the trunk -// return TreeHelper.getBranch(muse.state); -// } -// } -// -// return null; -// } + private BranchBlock setBranchToShellMuse(Level world, BlockState state) { + + Block block = state.getBlock(); + if (block instanceof TrunkShellBlock){ + TrunkShellBlock.ShellMuse muse = ((TrunkShellBlock)block).getMuse(world, state, startCutPos); + if (muse != null){ + startCutPos = muse.pos(); //the cut pos is moved to the center of the trunk + return TreeHelper.getBranch(muse.state()); + } + } + + return null; + } }