Skip to content

Commit

Permalink
feat: Int provider trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jun 21, 2024
1 parent 60a40ea commit 1ed78a9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
org.gradle.debug=false

mod_version=1.0.80
mod_version=1.0.81

# Mod
mod_id=zenith
Expand Down
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);
}
}
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));

}

0 comments on commit 1ed78a9

Please sign in to comment.