-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/org/violetmoon/quark/content/world/feature/AncientTreeTopperDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.violetmoon.quark.content.world.feature; | ||
|
||
import java.util.Comparator; | ||
import java.util.Optional; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Vec3i; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecorator; | ||
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType; | ||
import org.violetmoon.quark.content.world.module.AncientWoodModule; | ||
|
||
//for Ancient Trees, TODO register me | ||
public class AncientTreeTopperDecorator extends TreeDecorator { | ||
|
||
public static final Codec<AncientTreeTopperDecorator> CODEC = Codec.unit(AncientTreeTopperDecorator::new); | ||
public static final TreeDecoratorType<AncientTreeTopperDecorator> TYPE = new TreeDecoratorType<>(CODEC); | ||
|
||
//TODO register me | ||
@Override | ||
protected TreeDecoratorType<?> type() { | ||
//return TYPE; | ||
return null; | ||
} | ||
|
||
@Override | ||
public void place(Context ctx) { | ||
Optional<BlockPos> highestLog = ctx.logs().stream().max(Comparator.comparingInt(Vec3i::getY)); | ||
if(highestLog.isPresent()) { | ||
BlockPos top = highestLog.get(); | ||
|
||
ImmutableSet<BlockPos> leafPos = ImmutableSet.of( | ||
top.above(), top.east(), top.west(), top.north(), top.south() | ||
); | ||
|
||
BlockState state = AncientWoodModule.ancient_leaves.defaultBlockState(); | ||
leafPos.forEach(p -> { | ||
if(ctx.isAir(p)) | ||
ctx.setBlock(p, state); | ||
}); | ||
} | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
...main/java/org/violetmoon/quark/content/world/feature/MultiFoliageStraightTrunkPlacer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.violetmoon.quark.content.world.feature; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
import java.util.stream.Collectors; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.world.level.LevelSimulatedReader; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration; | ||
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer; | ||
import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacer; | ||
import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType; | ||
|
||
//for Ancient Saplings, TODO register me | ||
public class MultiFoliageStraightTrunkPlacer extends TrunkPlacer { | ||
final int foliageDistance; | ||
final int maxBlobs; | ||
|
||
public MultiFoliageStraightTrunkPlacer(int baseHeight, int heightRandA, int heightRandB, int foliageDistance, int maxBlobs) { | ||
super(baseHeight, heightRandA, heightRandB); | ||
this.foliageDistance = foliageDistance; | ||
this.maxBlobs = maxBlobs; | ||
} | ||
|
||
public static final Codec<MultiFoliageStraightTrunkPlacer> CODEC = RecordCodecBuilder.create(overengineered -> | ||
trunkPlacerParts(overengineered).and( | ||
overengineered.group( | ||
Codec.INT.fieldOf("foliageDistance").forGetter(x -> x.foliageDistance), | ||
Codec.INT.fieldOf("maxBlobs").forGetter(x -> x.maxBlobs) | ||
) | ||
).apply(overengineered, MultiFoliageStraightTrunkPlacer::new)); | ||
|
||
//TODO: register me | ||
public static final TrunkPlacerType<MultiFoliageStraightTrunkPlacer> TYPE = new TrunkPlacerType<>(CODEC); | ||
|
||
@Override | ||
protected TrunkPlacerType<?> type() { | ||
//return TYPE; | ||
return null; | ||
} | ||
|
||
@Override | ||
public List<FoliagePlacer.FoliageAttachment> placeTrunk(LevelSimulatedReader level, BiConsumer<BlockPos, BlockState> placer, RandomSource random, int idk, BlockPos rootPos, TreeConfiguration cfg) { | ||
setDirtAt(level, placer, random, rootPos.below(), cfg); | ||
|
||
List<BlockPos> folliagePositions = new ArrayList<>(); | ||
|
||
int placed = 0; | ||
int j = 0; | ||
for(int i = idk; i >= 0; --i) { | ||
BlockPos target = rootPos.above(i); | ||
this.placeLog(level, placer, random, target, cfg); | ||
|
||
if(placed < maxBlobs) { | ||
if(j == 0) { | ||
folliagePositions.add(target); | ||
j = foliageDistance; | ||
placed++; | ||
} else j--; | ||
} | ||
|
||
} | ||
|
||
return folliagePositions.stream().map(p -> new FoliagePlacer.FoliageAttachment(p, 0, false)).collect(Collectors.toList()); | ||
} | ||
} |