-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
60a40ea
commit 1ed78a9
Showing
3 changed files
with
62 additions
and
1 deletion.
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
47 changes: 47 additions & 0 deletions
47
src/main/java/net/zepalesque/zenith/world/tree/trunk/IntProviderTrunkPlacer.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,47 @@ | ||
package net.zepalesque.zenith.world.tree.trunk; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.util.RandomSource; | ||
import net.minecraft.util.valueproviders.IntProvider; | ||
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; | ||
|
||
import java.util.List; | ||
import java.util.function.BiConsumer; | ||
|
||
public class IntProviderTrunkPlacer extends TrunkPlacer { | ||
public static final Codec<IntProviderTrunkPlacer> CODEC = IntProvider.CODEC.fieldOf("height").xmap(IntProviderTrunkPlacer::new, placer -> placer.height).stable().codec(); | ||
|
||
protected final IntProvider height; | ||
public IntProviderTrunkPlacer(IntProvider height) { | ||
super(0, 0, 0); | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
protected TrunkPlacerType<?> type() { | ||
return ZenithTrunkPlacers.INT_PROVIDER.get(); | ||
} | ||
|
||
@Override | ||
public List<FoliagePlacer.FoliageAttachment> placeTrunk(LevelSimulatedReader level, BiConsumer<BlockPos, BlockState> setter, RandomSource random, int height, BlockPos origin, TreeConfiguration config) { | ||
setDirtAt(level, setter, random, origin.below(), config); | ||
|
||
for(int i = 0; i < height; ++i) { | ||
this.placeLog(level, setter, random, origin.above(i), config); | ||
} | ||
|
||
return ImmutableList.of(new FoliagePlacer.FoliageAttachment(origin.above(height), 0, false)); | ||
} | ||
|
||
@Override | ||
public int getTreeHeight(RandomSource random) { | ||
return this.height.sample(random); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/net/zepalesque/zenith/world/tree/trunk/ZenithTrunkPlacers.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,14 @@ | ||
package net.zepalesque.zenith.world.tree.trunk; | ||
|
||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.zepalesque.zenith.Zenith; | ||
|
||
public class ZenithTrunkPlacers { | ||
public static final DeferredRegister<TrunkPlacerType<?>> TRUNK_PLACERS = DeferredRegister.create(BuiltInRegistries.TRUNK_PLACER_TYPE, Zenith.MODID); | ||
|
||
public static final DeferredHolder<TrunkPlacerType<?>, TrunkPlacerType<IntProviderTrunkPlacer>> INT_PROVIDER = TRUNK_PLACERS.register("int_provider_trunk", () -> new TrunkPlacerType<>(IntProviderTrunkPlacer.CODEC)); | ||
|
||
} |