Skip to content

Commit

Permalink
Add new option to make all log items spawn in one place (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda authored Jun 29, 2024
1 parent 67e4e7d commit 60faaaf
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ public interface ITreeConfiguration{
boolean isBreakNetherTreeWarts();

boolean isBreakMangroveRoots();

int getSearchAreaRadius();

@NotNull
AdjacentStopMode getAdjacentStopMode();

boolean isSpawnItemsAtBreakPoint();
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,9 @@ public int getSearchAreaRadius(){
public AdjacentStopMode getAdjacentStopMode(){
return delegate.getAdjacentStopMode();
}

@Override
public boolean isSpawnItemsAtBreakPoint(){
return delegate.isSpawnItemsAtBreakPoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IBlock> deniedLeavesCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
}
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/fallingtree/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -264,6 +270,7 @@ public class ClothConfigHook extends ClothHookBase{
trees.addEntry(searchAreaRadiusEntry);
trees.addEntry(allowedAdjacentBlocks);
trees.addEntry(adjacentStopModeEntry);
trees.addEntry(spawnItemsAtBreakPointEntry);
}

@OnlyIn(Dist.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit 60faaaf

Please sign in to comment.