Skip to content

Commit

Permalink
Sort of fix #2008
Browse files Browse the repository at this point in the history
This fix only applies to Forge/Fabric, and it still produces floating
trees... but it's better than nothing
  • Loading branch information
octylFractal committed Jun 8, 2022
1 parent 31e5298 commit d94b5ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.TreeFeature;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.ServerLevelData;
Expand Down Expand Up @@ -459,10 +461,19 @@ public boolean generateTree(TreeType type, EditSession editSession, BlockVector3
if (type == TreeType.CHORUS_PLANT) {
position = position.add(0, 1, 0);
}
return generator != null && generator.place(
world, chunkManager.getGenerator(), random,
FabricAdapter.toBlockPos(position)
);
if (generator == null) {
return false;
}
BlockPos blockPos = FabricAdapter.toBlockPos(position);
// Manual override of the chunk generator to prevent the tree from generating in non-dirt
if (generator.feature() instanceof TreeFeature && !isTreePosition(world, blockPos)) {
return false;
}
return generator.place(world, chunkManager.getGenerator(), random, blockPos);
}

private static boolean isTreePosition(ServerLevel world, BlockPos blockPos) {
return world.isStateAtPosition(blockPos.below(), Feature::isDirt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.TreeFeature;
import net.minecraft.world.level.storage.LevelData;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.PrimaryLevelData;
Expand Down Expand Up @@ -447,9 +449,19 @@ public boolean generateTree(TreeType type, EditSession editSession, BlockVector3
if (type == TreeType.CHORUS_PLANT) {
position = position.add(0, 1, 0);
}
return generator != null && generator.place(
world, chunkManager.getGenerator(), random, ForgeAdapter.toBlockPos(position)
);
if (generator == null) {
return false;
}
BlockPos blockPos = ForgeAdapter.toBlockPos(position);
// Manual override of the chunk generator to prevent the tree from generating in non-dirt
if (generator.feature() instanceof TreeFeature && !isTreePosition(world, blockPos)) {
return false;
}
return generator.place(world, chunkManager.getGenerator(), random, blockPos);
}

private static boolean isTreePosition(ServerLevel world, BlockPos blockPos) {
return world.isStateAtPosition(blockPos.below(), Feature::isDirt);
}

@Override
Expand Down

0 comments on commit d94b5ae

Please sign in to comment.