From 583f30560a99786ae17764e1972284b271659cda Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Mon, 27 Jan 2025 01:39:18 -0500 Subject: [PATCH] i suck --- .../impl/foliage/MapleFoliagePlacer.java | 29 +++-- .../impl/foliage/RoundMapleFoliagePlacer.java | 105 ++---------------- 2 files changed, 28 insertions(+), 106 deletions(-) diff --git a/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/MapleFoliagePlacer.java b/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/MapleFoliagePlacer.java index 7823652c40..8bdbebf3d5 100644 --- a/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/MapleFoliagePlacer.java +++ b/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/MapleFoliagePlacer.java @@ -18,6 +18,7 @@ package net.frozenblock.wilderwild.worldgen.impl.foliage; +import com.mojang.datafixers.Products; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.frozenblock.wilderwild.registry.WWFeatures; @@ -29,15 +30,23 @@ import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer; import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; public class MapleFoliagePlacer extends FoliagePlacer { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec( - (instance) -> foliagePlacerParts(instance) - .and(IntProvider.codec(0, 24).fieldOf("length").forGetter((placer) -> placer.length)) - .apply(instance, MapleFoliagePlacer::new) + (instance) -> mapleFoliagePlacerParts(instance).apply(instance, MapleFoliagePlacer::new) ); - private final IntProvider length; + + @Contract("_ -> new") + protected static

Products.@NotNull P3, IntProvider, IntProvider, IntProvider> mapleFoliagePlacerParts( + RecordCodecBuilder.Instance

instance + ) { + return foliagePlacerParts(instance) + .and(IntProvider.codec(0, 24).fieldOf("length").forGetter((placer) -> placer.length)); + } + + protected final IntProvider length; public MapleFoliagePlacer(IntProvider radius, IntProvider offset, IntProvider foliageHeight) { super(radius, offset); @@ -85,8 +94,7 @@ protected void placeLeavesInCircle( int trunkHeight ) { BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); - Vec3 center = centerPos.getCenter(); - double radius = providedRadius + ((random.nextDouble() - 0.5D) * 0.4D); + double radius = providedRadius + ((random.nextDouble() - this.getRandomRadiusShrink()) * 0.4D); double increment = radius * 0.05D; for (double j = -radius; j <= radius; j += increment) { @@ -99,6 +107,10 @@ protected void placeLeavesInCircle( } } + protected double getRandomRadiusShrink() { + return -0.5D; + } + protected boolean shouldSkipMapleLocationSigned( double dx, double dz, double radius, boolean giantTrunk, int totalHeight, int currentHeight, int trunkHeight ) { @@ -119,12 +131,11 @@ protected boolean shouldSkipMapleLocation( double xDistance, double zDistance, double radius, int totalHeight, int currentHeight, int trunkHeight ) { double mapleFunction = this.getMapleFoliageFunction(totalHeight, currentHeight, radius, currentHeight <= trunkHeight); - Vec3 vec3 = new Vec3(xDistance, 0, zDistance); - double distance = Vec3.ZERO.distanceTo(vec3); + double distance = new Vec3(xDistance, 0, zDistance).horizontalDistance(); return distance > mapleFunction && distance > 0.4D; } - private double getMapleFoliageFunction( + protected double getMapleFoliageFunction( double totalHeight, double height, double radius, diff --git a/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/RoundMapleFoliagePlacer.java b/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/RoundMapleFoliagePlacer.java index 71670d2828..f174ecdf84 100644 --- a/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/RoundMapleFoliagePlacer.java +++ b/src/main/java/net/frozenblock/wilderwild/worldgen/impl/foliage/RoundMapleFoliagePlacer.java @@ -21,27 +21,17 @@ import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.frozenblock.wilderwild.registry.WWFeatures; -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.levelgen.feature.configurations.TreeConfiguration; -import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer; import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType; -import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; -public class RoundMapleFoliagePlacer extends FoliagePlacer { +public class RoundMapleFoliagePlacer extends MapleFoliagePlacer { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec( - (instance) -> foliagePlacerParts(instance) - .and(IntProvider.codec(0, 24).fieldOf("length").forGetter((placer) -> placer.length)) - .apply(instance, RoundMapleFoliagePlacer::new) + (instance) -> mapleFoliagePlacerParts(instance).apply(instance, RoundMapleFoliagePlacer::new) ); - private final IntProvider length; public RoundMapleFoliagePlacer(IntProvider radius, IntProvider offset, IntProvider foliageHeight) { - super(radius, offset); - this.length = foliageHeight; + super(radius, offset, foliageHeight); } @Override @@ -50,87 +40,18 @@ public RoundMapleFoliagePlacer(IntProvider radius, IntProvider offset, IntProvid } @Override - protected void createFoliage( - LevelSimulatedReader world, - FoliageSetter placer, - @NotNull RandomSource random, - TreeConfiguration config, - int trunkHeight, - @NotNull FoliageAttachment node, - int foliageHeight, - int radius, - int offset - ) { - BlockPos blockPos = node.pos(); - int totalHeight = offset + foliageHeight; - int currentHeight = totalHeight; - - for (int l = offset; l >= -foliageHeight; l--) { - this.placeLeavesInCircle(world, placer, random, config, blockPos, radius, l, node.doubleTrunk(), totalHeight, currentHeight, foliageHeight); - currentHeight -= 1; - } - } - - protected void placeLeavesInCircle( - LevelSimulatedReader world, - FoliageSetter placer, - @NotNull RandomSource random, - TreeConfiguration config, - BlockPos centerPos, - int providedRadius, - int y, - boolean giantTrunk, - int totalHeight, - int currentHeight, - int trunkHeight - ) { - BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(); - double radius = providedRadius + ((random.nextDouble() - 0.3D) * 0.5D); - double increment = radius * 0.05D; - - for (double j = -radius; j <= radius; j += increment) { - for (double k = -radius; k <= radius; k += increment) { - if (!this.shouldSkipMapleLocationSigned(j, k, radius, giantTrunk, totalHeight, currentHeight, trunkHeight)) { - mutableBlockPos.setWithOffset(centerPos, (int) j, y, (int) k); - tryPlaceLeaf(world, placer, random, config, mutableBlockPos); - } - } - } + protected double getRandomRadiusShrink() { + return -0.3D; } - protected boolean shouldSkipMapleLocationSigned( - double dx, double dz, double radius, boolean giantTrunk, int totalHeight, int currentHeight, int trunkHeight - ) { - double i; - double j; - if (giantTrunk) { - i = Math.min(Math.abs(dx), Math.abs(dx - 1)); - j = Math.min(Math.abs(dz), Math.abs(dz - 1)); - } else { - i = Math.abs(dx); - j = Math.abs(dz); - } - - return this.shouldSkipMapleLocation(i, j, radius, totalHeight, currentHeight, trunkHeight); - } - - protected boolean shouldSkipMapleLocation( - double xDistance, double zDistance, double radius, int totalHeight, int currentHeight, int trunkHeight - ) { - double mapleFunction = this.getMapleFoliageFunction(totalHeight, currentHeight, radius, currentHeight <= trunkHeight); - Vec3 vec3 = new Vec3(xDistance, 0, zDistance); - double distance = Vec3.ZERO.distanceTo(vec3); - return distance > mapleFunction && distance > 0.4D; - } - - private double getMapleFoliageFunction( + @Override + protected double getMapleFoliageFunction( double totalHeight, double height, double radius, boolean hot ) { - double flippedHeight = totalHeight - height; - double function = Math.sin((flippedHeight * Math.PI) / totalHeight); + double function = Math.sin(((height * Math.PI) + (totalHeight * 0.5F)) / totalHeight); double finalFunction = (function * (radius - 1)) + 1D; double min = 0D; @@ -140,14 +61,4 @@ private double getMapleFoliageFunction( return Math.max(finalFunction, min); } - - @Override - public int foliageHeight(RandomSource random, int trunkHeight, TreeConfiguration config) { - return Math.max(5, trunkHeight - this.length.sample(random)); - } - - @Override - protected boolean shouldSkipLocation(RandomSource random, int dx, int y, int dz, int radius, boolean giantTrunk) { - return false; - } }