Skip to content

Commit 0865250

Browse files
committed
added check to offset trees when generating over foliage
1 parent e8d1827 commit 0865250

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
modName=DynamicTrees
22
modId=dynamictrees
3-
modVersion=1.4.4
3+
modVersion=1.4.5
44

55
group=com.ferreusveritas.dynamictrees
66

src/main/java/com/ferreusveritas/dynamictrees/worldgen/DynamicTreeFeature.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ protected void generateTrees(LevelContext levelContext, BiomeDatabase biomeDatab
8484
}
8585
}
8686

87+
private BlockPos OffsetPosIfOnFoliage(LevelAccessor level, BlockPos groundPos){
88+
if (isNonReplaceableFoliage(level, groundPos)){
89+
if (isNonReplaceableFoliage(level, groundPos.below())){
90+
return groundPos.below(2);
91+
}
92+
return groundPos.below();
93+
}
94+
return groundPos;
95+
}
96+
97+
private boolean isNonReplaceableFoliage(LevelAccessor pLevel, BlockPos pPos){
98+
BlockState state = pLevel.getBlockState(pPos);
99+
return !state.isAir() && validTreePos(pLevel, pPos);
100+
}
101+
87102
public static boolean validTreePos(LevelSimulatedReader pLevel, BlockPos pPos) {
88103
return pLevel.isStateAtPosition(pPos, (state) ->
89104
state.isAir() || state.is(BlockTags.REPLACEABLE_BY_TREES) || state.is(DTBlockTags.FOLIAGE));
@@ -94,6 +109,8 @@ protected GeneratorResult generateTree(LevelContext levelContext, BiomeDatabase.
94109
return GeneratorResult.NO_GROUND;
95110
}
96111

112+
groundPos = OffsetPosIfOnFoliage(levelContext.accessor(), groundPos);;
113+
97114
// If there is already a rooty block, a cave rooted tree has taken this disc, so ignore
98115
if (levelContext.accessor().getBlockState(groundPos).getBlock() instanceof RootyBlock) {
99116
return GeneratorResult.ALREADY_GENERATED;

0 commit comments

Comments
 (0)