From 60faaaf058a2ac067c086658e87a54f8275ac7a4 Mon Sep 17 00:00:00 2001 From: Thomas <1688389+Rakambda@users.noreply.github.com> Date: Sat, 29 Jun 2024 15:47:32 +0200 Subject: [PATCH] Add new option to make all log items spawn in one place (#720) --- .../common/config/ITreeConfiguration.java | 3 +- .../config/proxy/TreeProxyConfiguration.java | 5 +++ .../common/config/real/TreeConfiguration.java | 2 + .../InstantaneousTreeBreakingHandler.java | 9 +++- .../tree/breaking/LeafForceBreaker.java | 42 +++++++++---------- .../assets/fallingtree/lang/en_us.json | 2 + .../fabric/client/cloth/ClothConfigHook.java | 7 ++++ .../cloth/ClothConfigHook.java.disabled | 7 ++++ .../client/cloth/ClothConfigHook.java | 7 ++++ 9 files changed, 61 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/fr/rakambda/fallingtree/common/config/ITreeConfiguration.java b/common/src/main/java/fr/rakambda/fallingtree/common/config/ITreeConfiguration.java index 9e26e274..40ba3878 100644 --- a/common/src/main/java/fr/rakambda/fallingtree/common/config/ITreeConfiguration.java +++ b/common/src/main/java/fr/rakambda/fallingtree/common/config/ITreeConfiguration.java @@ -68,9 +68,10 @@ public interface ITreeConfiguration{ boolean isBreakNetherTreeWarts(); boolean isBreakMangroveRoots(); - int getSearchAreaRadius(); @NotNull AdjacentStopMode getAdjacentStopMode(); + + boolean isSpawnItemsAtBreakPoint(); } diff --git a/common/src/main/java/fr/rakambda/fallingtree/common/config/proxy/TreeProxyConfiguration.java b/common/src/main/java/fr/rakambda/fallingtree/common/config/proxy/TreeProxyConfiguration.java index 2595d6f2..bb0815b2 100644 --- a/common/src/main/java/fr/rakambda/fallingtree/common/config/proxy/TreeProxyConfiguration.java +++ b/common/src/main/java/fr/rakambda/fallingtree/common/config/proxy/TreeProxyConfiguration.java @@ -164,4 +164,9 @@ public int getSearchAreaRadius(){ public AdjacentStopMode getAdjacentStopMode(){ return delegate.getAdjacentStopMode(); } + + @Override + public boolean isSpawnItemsAtBreakPoint(){ + return delegate.isSpawnItemsAtBreakPoint(); + } } diff --git a/common/src/main/java/fr/rakambda/fallingtree/common/config/real/TreeConfiguration.java b/common/src/main/java/fr/rakambda/fallingtree/common/config/real/TreeConfiguration.java index cc204a3d..d5e93ec1 100644 --- a/common/src/main/java/fr/rakambda/fallingtree/common/config/real/TreeConfiguration.java +++ b/common/src/main/java/fr/rakambda/fallingtree/common/config/real/TreeConfiguration.java @@ -78,6 +78,8 @@ public class TreeConfiguration implements ITreeConfiguration, IResettable{ @Expose @NotNull private AdjacentStopMode adjacentStopMode = AdjacentStopMode.STOP_ALL; + @Expose + private boolean spawnItemsAtBreakPoint = false; //Cache private Set deniedLeavesCache; diff --git a/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/InstantaneousTreeBreakingHandler.java b/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/InstantaneousTreeBreakingHandler.java index e7103663..23c038f4 100644 --- a/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/InstantaneousTreeBreakingHandler.java +++ b/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/InstantaneousTreeBreakingHandler.java @@ -49,7 +49,14 @@ public boolean breakTree(@NotNull IPlayer player, @NotNull Tree tree) throws Bre player.awardItemUsed(tool.getItem()); if(!player.isCreative() || mod.getConfiguration().isLootInCreative()){ - logState.getBlock().playerDestroy(level, player, logBlockPos, logState, level.getBlockEntity(logBlockPos), tool); + logState.getBlock().playerDestroy( + level, + player, + mod.getConfiguration().getTrees().isSpawnItemsAtBreakPoint() ? tree.getHitPos() : logBlockPos, + logState, + level.getBlockEntity(logBlockPos), + tool + ); } var isRemoved = level.removeBlock(logBlockPos, false); return isRemoved ? 1 : 0; diff --git a/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/LeafForceBreaker.java b/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/LeafForceBreaker.java index 91ec3af9..b747fe09 100644 --- a/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/LeafForceBreaker.java +++ b/common/src/main/java/fr/rakambda/fallingtree/common/tree/breaking/LeafForceBreaker.java @@ -10,26 +10,26 @@ @Log4j2 @RequiredArgsConstructor -public class LeafForceBreaker { - private final FallingTreeCommon mod; +public class LeafForceBreaker{ + private final FallingTreeCommon mod; - public void forceBreakDecayLeaves(@NotNull IPlayer player, @NotNull Tree tree, @NotNull ILevel level) { - var radius = mod.getConfiguration().getTrees().getLeavesBreakingForceRadius(); - if (radius > 0) { - tree.getTopMostLog().ifPresent(topLog -> { - var start = topLog.offset(-radius, -radius, -radius); - var end = topLog.offset(radius, radius, radius); - topLog.betweenClosedStream(start, end).forEach(checkPos -> { - var checkState = level.getBlockState(checkPos); - var checkBlock = checkState.getBlock(); - if (mod.isLeafBlock(checkBlock)) { - if (!player.isCreative() || mod.getConfiguration().isLootInCreative()) { - checkState.dropResources(level, checkPos); - } - level.removeBlock(checkPos, false); - } - }); - }); - } - } + public void forceBreakDecayLeaves(@NotNull IPlayer player, @NotNull Tree tree, @NotNull ILevel level){ + var radius = mod.getConfiguration().getTrees().getLeavesBreakingForceRadius(); + if(radius > 0){ + tree.getTopMostLog().ifPresent(topLog -> { + var start = topLog.offset(-radius, -radius, -radius); + var end = topLog.offset(radius, radius, radius); + topLog.betweenClosedStream(start, end).forEach(checkPos -> { + var checkState = level.getBlockState(checkPos); + var checkBlock = checkState.getBlock(); + if(mod.isLeafBlock(checkBlock)){ + if(!player.isCreative() || mod.getConfiguration().isLootInCreative()){ + checkState.dropResources(level, mod.getConfiguration().getTrees().isSpawnItemsAtBreakPoint() ? tree.getHitPos() : checkPos); + } + level.removeBlock(checkPos, false); + } + }); + }); + } + } } diff --git a/common/src/main/resources/assets/fallingtree/lang/en_us.json b/common/src/main/resources/assets/fallingtree/lang/en_us.json index 23a8b599..530db16d 100644 --- a/common/src/main/resources/assets/fallingtree/lang/en_us.json +++ b/common/src/main/resources/assets/fallingtree/lang/en_us.json @@ -60,6 +60,8 @@ "text.autoconfig.fallingtree.option.trees.allowedAdjacentBlocks.@Tooltip": "Define a list of blocks that are allowed to be next to the trunk of the tree. If a block that isn't in that list is found around the trunk then the tree won't be cut according to the adjacentStopMode property.\n\nINFO: If this is empty no restriction will be applied.", "text.autoconfig.fallingtree.option.trees.adjacentStopMode": "Adjacent stop mode", "text.autoconfig.fallingtree.option.trees.adjacentStopMode.@Tooltip": "Defines what happens when an adjacent block that isn't allowed is found.\n\nSTOP_ALL will make it so that the tree isn't cut at all.\nSTOP_BRANCH will stop the current branch but still cut the rest of the tree and up to the adjacent block.", + "text.autoconfig.fallingtree.option.trees.spawnItemsAtBreakPoint": "Spawn logs at break point", + "text.autoconfig.fallingtree.option.trees.spawnItemsAtBreakPoint.@Tooltip": "If enabled, all logs will spawn where the log was broken instead of at their own location.\n\nINFO: Only in INSTANTANEOUS mode.", "text.autoconfig.fallingtree.option.tools.allowed": "Allowed tools", "text.autoconfig.fallingtree.option.tools.allowed.@Tooltip": "Additional list of tools that can be used to chop down a tree.\n\nINFO: Items marked with the axe tag will already be allowed.", "text.autoconfig.fallingtree.option.tools.denied": "Denied tools", diff --git a/fabric/src/client/java/fr/rakambda/fallingtree/fabric/client/cloth/ClothConfigHook.java b/fabric/src/client/java/fr/rakambda/fallingtree/fabric/client/cloth/ClothConfigHook.java index 42882304..c238991e 100644 --- a/fabric/src/client/java/fr/rakambda/fallingtree/fabric/client/cloth/ClothConfigHook.java +++ b/fabric/src/client/java/fr/rakambda/fallingtree/fabric/client/cloth/ClothConfigHook.java @@ -239,6 +239,12 @@ private void fillTreesConfigScreen(@NotNull ConfigBuilder builder, @NotNull Tree .setTooltip(getTooltips("trees", "adjacentStopMode")) .setSaveConsumer(config::setAdjacentStopMode) .build(); + var spawnItemsAtBreakPointEntry = builder.entryBuilder() + .startBooleanToggle(translatable(getFieldName("trees", "spawnItemsAtBreakPoint")), config.isSpawnItemsAtBreakPoint()) + .setDefaultValue(false) + .setTooltip(getTooltips("trees", "spawnItemsAtBreakPoint")) + .setSaveConsumer(config::setSpawnItemsAtBreakPoint) + .build(); var trees = builder.getOrCreateCategory(translatable("text.autoconfig.fallingtree.category.trees")); trees.addEntry(breakModeEntry); @@ -264,6 +270,7 @@ private void fillTreesConfigScreen(@NotNull ConfigBuilder builder, @NotNull Tree trees.addEntry(searchAreaRadiusEntry); trees.addEntry(allowedAdjacentBlocks); trees.addEntry(adjacentStopModeEntry); + trees.addEntry(spawnItemsAtBreakPointEntry); } @Environment(EnvType.CLIENT) diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled b/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled index 2c8eec80..068302a6 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled @@ -239,6 +239,12 @@ public class ClothConfigHook extends ClothHookBase{ .setTooltip(getTooltips("trees", "adjacentStopMode")) .setSaveConsumer(config::setAdjacentStopMode) .build(); + var spawnItemsAtBreakPointEntry = builder.entryBuilder() + .startBooleanToggle(translatable(getFieldName("trees", "spawnItemsAtBreakPoint")), config.isSpawnItemsAtBreakPoint()) + .setDefaultValue(false) + .setTooltip(getTooltips("trees", "spawnItemsAtBreakPoint")) + .setSaveConsumer(config::setSpawnItemsAtBreakPoint) + .build(); var trees = builder.getOrCreateCategory(translatable("text.autoconfig.fallingtree.category.trees")); trees.addEntry(breakModeEntry); @@ -264,6 +270,7 @@ public class ClothConfigHook extends ClothHookBase{ trees.addEntry(searchAreaRadiusEntry); trees.addEntry(allowedAdjacentBlocks); trees.addEntry(adjacentStopModeEntry); + trees.addEntry(spawnItemsAtBreakPointEntry); } @OnlyIn(Dist.CLIENT) diff --git a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java index 70e7c297..ab7af58e 100644 --- a/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java +++ b/neoforge/src/main/java/fr/rakambda/fallingtree/neoforge/client/cloth/ClothConfigHook.java @@ -239,6 +239,12 @@ private void fillTreesConfigScreen(@NotNull ConfigBuilder builder, @NotNull Tree .setTooltip(getTooltips("trees", "adjacentStopMode")) .setSaveConsumer(config::setAdjacentStopMode) .build(); + var spawnItemsAtBreakPointEntry = builder.entryBuilder() + .startBooleanToggle(translatable(getFieldName("trees", "spawnItemsAtBreakPoint")), config.isSpawnItemsAtBreakPoint()) + .setDefaultValue(false) + .setTooltip(getTooltips("trees", "spawnItemsAtBreakPoint")) + .setSaveConsumer(config::setSpawnItemsAtBreakPoint) + .build(); var trees = builder.getOrCreateCategory(translatable("text.autoconfig.fallingtree.category.trees")); trees.addEntry(breakModeEntry); @@ -264,6 +270,7 @@ private void fillTreesConfigScreen(@NotNull ConfigBuilder builder, @NotNull Tree trees.addEntry(searchAreaRadiusEntry); trees.addEntry(allowedAdjacentBlocks); trees.addEntry(adjacentStopModeEntry); + trees.addEntry(spawnItemsAtBreakPointEntry); } @OnlyIn(Dist.CLIENT)