Reorganized Imports/Packages

This commit is contained in:
Frank 2022-05-18 23:56:18 +02:00
parent a8beba9196
commit 770a5b4046
854 changed files with 42775 additions and 41811 deletions

View file

@ -0,0 +1,17 @@
package org.betterx.betterend.integration.byg;
import net.minecraft.world.level.block.Block;
import org.betterx.bclib.blocks.BaseVineBlock;
import org.betterx.betterend.blocks.basis.EndWallPlantBlock;
import org.betterx.betterend.registry.EndBlocks;
public class BYGBlocks {
public static final Block IVIS_MOSS = EndBlocks.registerBlock("ivis_moss", new EndWallPlantBlock());
public static final Block NIGHTSHADE_MOSS = EndBlocks.registerBlock("nightshade_moss", new EndWallPlantBlock());
public static final Block IVIS_VINE = EndBlocks.registerBlock("ivis_vine", new BaseVineBlock());
public static void register() {
}
}

View file

@ -0,0 +1,26 @@
package org.betterx.betterend.integration.byg;
import org.betterx.bclib.integration.ModIntegration;
import org.betterx.betterend.integration.EndBiomeIntegration;
public class BYGIntegration extends ModIntegration implements EndBiomeIntegration {
public BYGIntegration() {
super("byg");
}
@Override
public void init() {
/*Block block = Integrations.BYG.getBlock("ivis_phylium");
if (block != null) {
TagAPI.addTags(block, CommonBlockTags.END_STONES, CommonBlockTags.GEN_END_STONES);
}
BYGBlocks.register();
BYGFeatures.register();
BYGBiomes.register();*/
}
@Override
public void addBiomes() {
//BYGBiomes.addBiomes();
}
}

View file

@ -0,0 +1,23 @@
package org.betterx.betterend.integration.byg.biomes;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.integration.Integrations;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.world.biome.EndBiome;
public class BYGBiomes {
// New Biomes
public static final EndBiome OLD_BULBIS_GARDENS = EndBiomes.registerSubBiomeIntegration(new OldBulbisGardens());
public static final EndBiome NIGHTSHADE_REDWOODS = EndBiomes.registerSubBiomeIntegration(new NightshadeRedwoods());
//public static final EndBiome ETHERIAL_GROVE = EndBiomes.registerSubBiomeIntegration(new EterialGrove());
public static void register() {
BetterEnd.LOGGER.info("Registered " + OLD_BULBIS_GARDENS);
}
public static void addBiomes() {
EndBiomes.addSubBiomeIntegration(OLD_BULBIS_GARDENS, Integrations.BYG.getID("bulbis_gardens"));
EndBiomes.addSubBiomeIntegration(NIGHTSHADE_REDWOODS, Integrations.BYG.getID("nightshade_forest"));
//EndBiomes.addSubBiomeIntegration(ETHERIAL_GROVE, Integrations.BYG.getID("ethereal_islands"));
}
}

View file

@ -0,0 +1,87 @@
package org.betterx.betterend.integration.byg.biomes;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.betterend.integration.Integrations;
import org.betterx.betterend.integration.byg.features.BYGFeatures;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.world.biome.EndBiome;
import java.util.List;
public class NightshadeRedwoods extends EndBiome.Config {
public NightshadeRedwoods() {
super("nightshade_redwoods");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
Holder<Biome> biome = Integrations.BYG.getBiome("nightshade_forest");
BiomeSpecialEffects effects = biome.value().getSpecialEffects();
builder.fogColor(140, 108, 47)
.fogDensity(1.5F)
.waterAndFogColor(55, 70, 186)
.foliageColor(122, 17, 155)
.particles(
ParticleTypes.REVERSE_PORTAL,
0.002F
)
//TODO: 1.18 surface rules
// .setSurface(biome.getGenerationSettings()
// .getSurfaceBuilder()
// .get())
.grassColor(48, 13, 89)
.plantsColor(200, 125, 9)
.feature(EndFeatures.END_LAKE_RARE)
.feature(BYGFeatures.NIGHTSHADE_REDWOOD_TREE)
.feature(BYGFeatures.NIGHTSHADE_MOSS_WOOD)
.feature(BYGFeatures.NIGHTSHADE_MOSS);
if (BCLib.isClient()) {
SoundEvent loop = effects.getAmbientLoopSoundEvent()
.get();
SoundEvent music = effects.getBackgroundMusic()
.get()
.getEvent();
SoundEvent additions = effects.getAmbientAdditionsSettings()
.get()
.getSoundEvent();
SoundEvent mood = effects.getAmbientMoodSettings()
.get()
.getSoundEvent();
builder.loop(loop)
.music(music)
.additions(additions)
.mood(mood);
}
biome.value().getGenerationSettings()
.features()
.forEach((list) -> {
list.forEach((feature) -> {
builder.feature(Decoration.VEGETAL_DECORATION, feature);
});
});
for (MobCategory group : MobCategory.values()) {
List<SpawnerData> list = biome.value()
.getMobSettings()
.getMobs(group)
.unwrap();
list.forEach((entry) -> {
builder.spawn((EntityType<? extends Mob>) entry.type, 1, entry.minCount, entry.maxCount);
});
}
}
}

View file

@ -0,0 +1,120 @@
package org.betterx.betterend.integration.byg.biomes;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.betterend.integration.Integrations;
import org.betterx.betterend.integration.byg.features.BYGFeatures;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.world.biome.EndBiome;
import java.util.List;
import java.util.function.Supplier;
public class OldBulbisGardens extends EndBiome.Config {
public OldBulbisGardens() {
super("old_bulbis_gardens");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
Holder<Biome> biome = Integrations.BYG.getBiome("bulbis_gardens");
BiomeSpecialEffects effects = biome.value().getSpecialEffects();
Block ivis = Integrations.BYG.getBlock("ivis_phylium");
// Block origin = biome.getGenerationSettings()
// .getSurfaceBuilderConfig()
// .getTopMaterial()
// .getBlock();
builder.fogColor(215, 132, 207)
.fogDensity(1.8F)
.waterAndFogColor(40, 0, 56)
.foliageColor(122, 17, 155)
.particles(
ParticleTypes.REVERSE_PORTAL,
0.002F
)
//TODO: 1.18 surface rules
//.surface(ivis, origin)
.feature(EndFeatures.END_LAKE_RARE)
.feature(BYGFeatures.OLD_BULBIS_TREE);
if (BCLib.isClient()) {
SoundEvent loop = effects.getAmbientLoopSoundEvent()
.get();
SoundEvent music = effects.getBackgroundMusic()
.get()
.getEvent();
SoundEvent additions = effects.getAmbientAdditionsSettings()
.get()
.getSoundEvent();
SoundEvent mood = effects.getAmbientMoodSettings()
.get()
.getSoundEvent();
builder.loop(loop)
.music(music)
.additions(additions)
.mood(mood);
}
for (MobCategory group : MobCategory.values()) {
List<SpawnerData> list = biome.value()
.getMobSettings()
.getMobs(group)
.unwrap();
list.forEach((entry) -> {
builder.spawn((EntityType<? extends Mob>) entry.type, 1, entry.minCount, entry.maxCount);
});
}
List<HolderSet<PlacedFeature>> features = biome.value().getGenerationSettings()
.features();
HolderSet<PlacedFeature> vegetal = features.get(Decoration.VEGETAL_DECORATION.ordinal());
if (vegetal.size() > 2) {
Supplier<PlacedFeature> getter;
//TODO: 1.18.2 BRING BACK FEATURE COPY CODE
for (var placed : vegetal) {
System.out.print(placed);
}
// // Trees (first two features)
// // I couldn't process them with conditions, so that's why they are hardcoded (paulevs)
// for (int i = 0; i < 2; i++) {
// getter = vegetal.get(i);
// Holder<PlacedFeature> feature = getter.get();
// ResourceLocation id = BetterEnd.makeID("obg_feature_" + i);
// feature = Registry.register(
// BuiltinRegistries.PLACED_FEATURE,
// id,
// feature
// );
// builder.feature(Decoration.VEGETAL_DECORATION, feature);
// }
// // Grasses and other features
// for (int i = 2; i < vegetal.size(); i++) {
// getter = vegetal.get(i);
// Holder<PlacedFeature> feature = getter.get();
// builder.feature(Decoration.VEGETAL_DECORATION, feature);
// }
}
builder.feature(EndFeatures.PURPLE_POLYPORE)
.feature(BYGFeatures.IVIS_MOSS_WOOD)
.feature(BYGFeatures.IVIS_MOSS)
.feature(BYGFeatures.IVIS_VINE)
.feature(BYGFeatures.IVIS_SPROUT);
}
}

View file

@ -0,0 +1,66 @@
package org.betterx.betterend.integration.byg.features;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.features.BCLCommonFeatures;
import org.betterx.bclib.world.features.BCLFeature;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.integration.Integrations;
import org.betterx.betterend.integration.byg.BYGBlocks;
import org.betterx.betterend.world.features.SinglePlantFeature;
import org.betterx.betterend.world.features.VineFeature;
import org.betterx.betterend.world.features.WallPlantFeature;
import org.betterx.betterend.world.features.WallPlantOnLogFeature;
public class BYGFeatures {
public static final BCLFeature OLD_BULBIS_TREE = redisterVegetation(
"old_bulbis_tree",
new OldBulbisTreeFeature(),
1
);
public static final BCLFeature IVIS_SPROUT = redisterVegetation(
"ivis_sprout",
new SinglePlantFeature(Integrations.BYG.getBlock("ivis_sprout"), 6, 2),
6
);
public static final BCLFeature IVIS_VINE = redisterVegetation(
"ivis_vine",
new VineFeature(BYGBlocks.IVIS_VINE, 24),
5
);
public static final BCLFeature IVIS_MOSS = redisterVegetation(
"ivis_moss",
new WallPlantFeature(BYGBlocks.IVIS_MOSS, 6),
1
);
public static final BCLFeature IVIS_MOSS_WOOD = redisterVegetation(
"ivis_moss_wood",
new WallPlantOnLogFeature(BYGBlocks.IVIS_MOSS, 6),
15
);
public static final BCLFeature NIGHTSHADE_MOSS = redisterVegetation(
"nightshade_moss",
new WallPlantFeature(BYGBlocks.NIGHTSHADE_MOSS, 5),
2
);
public static final BCLFeature NIGHTSHADE_MOSS_WOOD = redisterVegetation(
"nightshade_moss_wood",
new WallPlantOnLogFeature(BYGBlocks.NIGHTSHADE_MOSS, 5),
8
);
public static final BCLFeature NIGHTSHADE_REDWOOD_TREE = redisterVegetation(
"nightshade_redwood_tree",
new NightshadeRedwoodTreeFeature(),
1
);
public static final BCLFeature BIG_ETHER_TREE = redisterVegetation("big_ether_tree", new BigEtherTreeFeature(), 1);
public static void register() {
}
private static BCLFeature redisterVegetation(String name, Feature<NoneFeatureConfiguration> feature, int density) {
return BCLCommonFeatures.makeVegetationFeature(BetterEnd.makeID(name), feature, density);
}
}

View file

@ -0,0 +1,80 @@
package org.betterx.betterend.integration.byg.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.material.Material;
import com.google.common.base.Function;
import com.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.util.SplineHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.integration.Integrations;
import java.util.List;
public class BigEtherTreeFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
if (!world.getBlockState(pos.below()).is(CommonBlockTags.END_STONES)) return false;
BlockState log = Integrations.BYG.getDefaultState("ether_log");
BlockState wood = Integrations.BYG.getDefaultState("ether_wood");
Function<BlockPos, BlockState> splinePlacer = (bpos) -> {
return log;
};
Function<BlockState, Boolean> replace = (state) -> {
return state.is(CommonBlockTags.END_STONES) || state.getMaterial()
.equals(Material.PLANT) || state.getMaterial()
.isReplaceable();
};
int height = MHelper.randRange(40, 60, random);
List<Vector3f> trunk = SplineHelper.makeSpline(0, 0, 0, 0, height, 0, height / 4);
SplineHelper.offsetParts(trunk, random, 2F, 0, 2F);
SDF sdf = SplineHelper.buildSDF(trunk, 2.3F, 0.8F, splinePlacer);
int count = height / 15;
for (int i = 1; i < count; i++) {
float splinePos = (float) i / (float) count;
float startAngle = random.nextFloat() * MHelper.PI2;
float length = (1 - splinePos) * height * 0.4F;
int points = (int) (length / 3);
List<Vector3f> branch = SplineHelper.makeSpline(0, 0, 0, length, 0, 0, points < 2 ? 2 : points);
SplineHelper.powerOffset(branch, length, 2F);
int rotCount = MHelper.randRange(5, 7, random);
Vector3f start = SplineHelper.getPos(trunk, splinePos * (trunk.size() - 1));
for (int j = 0; j < rotCount; j++) {
float angle = startAngle + (float) j / rotCount * MHelper.PI2;
List<Vector3f> br = SplineHelper.copySpline(branch);
SplineHelper.offsetParts(br, random, 0, 1, 1);
SplineHelper.rotateSpline(br, angle);
SplineHelper.offset(br, start);
SplineHelper.fillSpline(br, world, wood, pos, replace);
}
}
sdf.setReplaceFunction((state) -> {
return state.is(CommonBlockTags.END_STONES) || state.getMaterial()
.equals(Material.PLANT) || state.getMaterial()
.isReplaceable();
}).addPostProcess((info) -> {
if (info.getState().equals(log) && (!info.getStateUp().equals(log) || !info.getStateDown().equals(log))) {
return wood;
}
return info.getState();
}).fillRecursive(world, pos);
return true;
}
}

View file

@ -0,0 +1,200 @@
package org.betterx.betterend.integration.byg.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.material.Material;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.sdf.PosInfo;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFDisplacement;
import org.betterx.bclib.sdf.operator.SDFFlatWave;
import org.betterx.bclib.sdf.operator.SDFSmoothUnion;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.util.SplineHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.integration.Integrations;
import java.util.List;
public class NightshadeRedwoodTreeFeature extends DefaultFeature {
private static final List<Vector3f> BRANCH;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
if (!world.getBlockState(pos.below()).is(CommonBlockTags.END_STONES)) return false;
BlockState log = Integrations.BYG.getDefaultState("nightshade_log");
BlockState wood = Integrations.BYG.getDefaultState("nightshade_wood");
BlockState leaves = Integrations.BYG.getDefaultState("nightshade_leaves");
BlockState leaves_flower = Integrations.BYG.getDefaultState("flowering_nightshade_leaves");
Function<BlockPos, BlockState> splinePlacer = (bpos) -> {
return log;
};
Function<BlockState, Boolean> replace = (state) -> {
return state.is(CommonBlockTags.END_STONES) || state.getMaterial()
.equals(Material.PLANT) || state.getMaterial()
.isReplaceable();
};
Function<PosInfo, BlockState> post = (info) -> {
if (info.getState().equals(log) && (!info.getStateUp().equals(log) || !info.getStateDown().equals(log))) {
return wood;
}
return info.getState();
};
Function<BlockState, Boolean> ignore = (state) -> {
return state.equals(log) || state.equals(wood);
};
int height = MHelper.randRange(40, 60, random);
List<Vector3f> trunk = SplineHelper.makeSpline(0, 0, 0, 0, height, 0, height / 4);
SplineHelper.offsetParts(trunk, random, 0.8F, 0, 0.8F);
if (!SplineHelper.canGenerate(trunk, pos, world, replace)) {
return false;
}
int count = height >> 2;
float start = trunk.size() / 3F;
float delta = trunk.size() * 0.6F;
float max = height - 7;
float startAngle = random.nextFloat() * MHelper.PI2;
for (int i = 0; i < count; i++) {
float scale = (float) (count - i) / count * 15;
Vector3f offset = SplineHelper.getPos(trunk, (float) i / count * delta + start);
if (offset.y() > max) {
break;
}
List<Vector3f> branch = SplineHelper.copySpline(BRANCH);
SplineHelper.rotateSpline(branch, i * 1.3F + startAngle);
SplineHelper.scale(branch, scale);
SplineHelper.offsetParts(branch, random, 0.3F, 0.3F, 0.3F);
SplineHelper.offset(branch, offset);
SplineHelper.fillSpline(branch, world, wood, pos, replace);
}
SDF sdf = SplineHelper.buildSDF(trunk, 2.3F, 0.8F, splinePlacer);
SDF roots = new SDFSphere().setRadius(2F).setBlock(log);
roots = new SDFFlatWave().setIntensity(2F)
.setRaysCount(MHelper.randRange(5, 7, random))
.setAngle(random.nextFloat() * MHelper.PI2)
.setSource(roots);
sdf = new SDFSmoothUnion().setRadius(2F).setSourceA(sdf).setSourceB(roots);
sdf.setReplaceFunction(replace).addPostProcess(post).fillRecursive(world, pos);
Vector3f last = SplineHelper.getPos(trunk, trunk.size() - 1.35F);
for (int y = 0; y < 8; y++) {
BlockPos p = pos.offset(last.x() + 0.5, last.y() + y, last.z() + 0.5);
BlocksHelper.setWithoutUpdate(world, p, y == 4 ? wood : log);
}
for (int y = 0; y < 16; y++) {
BlockPos p = pos.offset(last.x() + 0.5, last.y() + y, last.z() + 0.5);
if (world.isEmptyBlock(p)) {
BlocksHelper.setWithoutUpdate(world, p, leaves);
}
float radius = (1 - y / 16F) * 3F;
int rad = (int) (radius + 1);
radius *= radius;
for (int x = -rad; x <= rad; x++) {
int x2 = x * x;
for (int z = -rad; z <= rad; z++) {
int z2 = z * z;
if (x2 + z2 < radius - random.nextFloat() * rad) {
BlockPos lp = p.offset(x, 0, z);
if (world.isEmptyBlock(lp)) {
BlocksHelper.setWithoutUpdate(world, lp, leaves);
}
}
}
}
}
MutableBlockPos mut = new MutableBlockPos();
Function<PosInfo, BlockState> leavesPost1 = (info) -> {
if (info.getState().equals(log) || info.getState().equals(wood)) {
for (int x = -6; x < 7; x++) {
int ax = Math.abs(x);
mut.setX(x + info.getPos().getX());
for (int z = -6; z < 7; z++) {
int az = Math.abs(z);
mut.setZ(z + info.getPos().getZ());
for (int y = -6; y < 7; y++) {
int ay = Math.abs(y);
int d = ax + ay + az;
if (d < 7) {
mut.setY(y + info.getPos().getY());
BlockState state = info.getState(mut);
if (state.getBlock() instanceof LeavesBlock) {
int distance = state.getValue(LeavesBlock.DISTANCE);
if (d < distance) {
info.setState(mut, state.setValue(LeavesBlock.DISTANCE, d));
}
}
}
}
}
}
}
return info.getState();
};
Function<PosInfo, BlockState> leavesPost2 = (info) -> {
if (info.getState().getBlock() instanceof LeavesBlock) {
int distance = info.getState().getValue(LeavesBlock.DISTANCE);
if (distance > MHelper.randRange(2, 4, random)) {
return Blocks.AIR.defaultBlockState();
}
for (Direction d : BlocksHelper.DIRECTIONS) {
int airCount = 0;
if (info.getState(d).isAir()) {
airCount++;
}
if (airCount > 5) {
return Blocks.AIR.defaultBlockState();
}
}
if (random.nextInt(8) == 0) {
return leaves_flower.setValue(LeavesBlock.DISTANCE, distance);
}
}
return info.getState();
};
SDF canopy = new SDFCappedCone().setRadius1(12F).setRadius2(1f).setHeight(height * 0.3F).setBlock(leaves);
canopy = new SDFDisplacement().setFunction((vec) -> {
return MHelper.randRange(-3F, 3F, random);
}).setSource(canopy);
canopy.addPostProcess(leavesPost1)
.addPostProcess(leavesPost2)
.fillRecursiveIgnore(world, pos.offset(0, height * 0.75, 0), ignore);
return true;
}
static {
BRANCH = Lists.newArrayList(
new Vector3f(0, 0, 0),
new Vector3f(0.25F, 0.1F, 0),
new Vector3f(0.40F, 0.2F, 0),
new Vector3f(0.50F, 0.4F, 0),
new Vector3f(0.55F, 0.6F, 0)
);
}
}

View file

@ -0,0 +1,214 @@
package org.betterx.betterend.integration.byg.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import com.google.common.collect.Lists;
import com.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFDisplacement;
import org.betterx.bclib.sdf.operator.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.operator.SDFUnion;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.util.SplineHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.integration.Integrations;
import org.betterx.betterend.noise.OpenSimplexNoise;
import java.util.List;
import java.util.function.Function;
public class OldBulbisTreeFeature extends DefaultFeature {
private static final List<Vector3f> SPLINE;
private static final List<Vector3f> ROOT;
private static final List<Vector3f> LEAF;
private static final List<Vector3f> SIDE;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
if (!world.getBlockState(pos.below()).is(CommonBlockTags.END_STONES)) return false;
if (!world.getBlockState(pos.below(4)).is(CommonBlockTags.GEN_END_STONES)) return false;
BlockState stem = Integrations.BYG.getDefaultState("bulbis_stem");
BlockState wood = Integrations.BYG.getDefaultState("bulbis_wood");
BlockState cap = Integrations.BYG.getDefaultState(random.nextBoolean()
? "bulbis_shell"
: "purple_bulbis_shell");
BlockState glow = Integrations.BYG.getDefaultState("purple_shroomlight");
Function<BlockState, Boolean> replacement = (state) -> {
if (state.equals(stem) || state.equals(wood) || state.is(CommonBlockTags.END_STONES) || state.getMaterial()
.equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
float size = MHelper.randRange(10, 20, random);
float addSize = MHelper.randRange(1, 1.7F, random);
float addRad = addSize * 0.5F + 0.5F;
int count = (int) (size * 0.15F);
size *= addSize;
float var = MHelper.PI2 / (float) (count * 3);
float start = MHelper.randRange(0, MHelper.PI2, random);
SDF sdf = null;
int x1 = ((pos.getX() >> 4) << 4) - 16;
int z1 = ((pos.getZ() >> 4) << 4) - 16;
AABB limits = new AABB(x1, pos.getY() - 5, z1, x1 + 47, pos.getY() + size * 2, z1 + 47);
for (int i = 0; i < count; i++) {
float angle = (float) i / (float) count * MHelper.PI2 + MHelper.randRange(0, var, random) + start;
List<Vector3f> spline = SplineHelper.copySpline(SPLINE);
float sizeXZ = (size + MHelper.randRange(0, size * 0.5F, random)) * 0.7F;
SplineHelper.scale(spline, sizeXZ, sizeXZ * 1.5F + MHelper.randRange(0, size * 0.5F, random), sizeXZ);
SplineHelper.offset(spline, new Vector3f(size * random.nextFloat() * 0.3F, 0, 0));
SplineHelper.rotateSpline(spline, angle);
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);// 1.3F 0.8F
SDF branch = SplineHelper.buildSDF(spline, 2.3F * addRad, 1.3F * addRad, (bpos) -> {
return stem;
});
Vector3f vec = spline.get(spline.size() - 1);
float radius = (size + MHelper.randRange(0, size * 0.5F, random)) * 0.35F;
bigSphere(world, pos.offset(vec.x(), vec.y(), vec.z()), radius, cap, glow, wood, replacement, random);
vec = SplineHelper.getPos(spline, 0.3F);
makeRoots(world, pos.offset(vec.x(), vec.y(), vec.z()), size * 0.4F + 5, random, wood, replacement);
sdf = (sdf == null) ? branch : new SDFUnion().setSourceA(sdf).setSourceB(branch);
}
sdf.setReplaceFunction(replacement).addPostProcess((info) -> {
if (info.getState().equals(stem) && (!info.getStateUp().equals(stem) || !info.getStateDown()
.equals(stem))) {
return wood;
}
return info.getState();
}).fillArea(world, pos, limits);
return true;
}
private void bigSphere(WorldGenLevel world,
BlockPos pos,
float radius,
BlockState cap,
BlockState glow,
BlockState wood,
Function<BlockState, Boolean> replacement,
RandomSource random) {
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
SDF sphere = new SDFSphere().setRadius(radius).setBlock(cap);
SDF sphereInner = new SDFSphere().setRadius(radius * 0.53F).setBlock(Blocks.AIR);
sphereInner = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.1, vec.y() * 0.1, vec.z() * 0.1);
}).setSource(sphereInner);
SDF sphereGlow = new SDFSphere().setRadius(radius * 0.6F).setBlock(glow);
sphereGlow = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.1, vec.y() * 0.1, vec.z() * 0.1) * 2F;
}).setSource(sphereGlow);
sphereGlow = new SDFSubtraction().setSourceA(sphereGlow).setSourceB(sphereInner);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sphereGlow);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sphereInner);
float offsetY = radius * 1.7F;
sphere = new SDFUnion().setSourceA(sphere).setSourceB(sphereGlow);
sphere = new SDFTranslate().setTranslate(0, offsetY, 0).setSource(sphere);
int leafCount = (int) (radius * 0.5F) + 2;
for (int i = 0; i < 4; i++) {
float angle = (float) i / 4 * MHelper.PI2;
List<Vector3f> spline = SplineHelper.copySpline(LEAF);
SplineHelper.rotateSpline(spline, angle);
SplineHelper.scale(spline, radius * 1.4F);
SplineHelper.fillSplineForce(spline, world, wood, pos, replacement);
for (int j = 0; j < leafCount; j++) {
float delta = ((float) j / (float) (leafCount - 1));
float scale = (float) Math.sin(delta * Math.PI) * 0.8F + 0.2F;
float index = Mth.lerp(delta, 1F, 3.9F);
Vector3f point = SplineHelper.getPos(spline, index);
List<Vector3f> side = SplineHelper.copySpline(SIDE);
SplineHelper.rotateSpline(side, angle);
SplineHelper.scale(side, scale * radius);
BlockPos p = pos.offset(point.x() + 0.5F, point.y() + 0.5F, point.z() + 0.5F);
SplineHelper.fillSplineForce(side, world, wood, p, replacement);
}
}
sphere.fillArea(world, pos, new AABB(pos.above((int) offsetY)).inflate(radius * 1.3F));
}
private void makeRoots(WorldGenLevel world,
BlockPos pos,
float radius,
RandomSource random,
BlockState wood,
Function<BlockState, Boolean> replacement) {
int count = (int) (radius * 1.5F);
for (int i = 0; i < count; i++) {
float angle = (float) i / (float) count * MHelper.PI2;
float scale = radius * MHelper.randRange(0.85F, 1.15F, random);
List<Vector3f> branch = SplineHelper.copySpline(ROOT);
SplineHelper.rotateSpline(branch, angle);
SplineHelper.scale(branch, scale);
Vector3f last = branch.get(branch.size() - 1);
if (world.getBlockState(pos.offset(last.x(), last.y(), last.z())).is(CommonBlockTags.GEN_END_STONES)) {
SplineHelper.fillSpline(branch, world, wood, pos, replacement);
}
}
}
static {
SPLINE = Lists.newArrayList(
new Vector3f(0.00F, 0.00F, 0.00F),
new Vector3f(0.10F, 0.35F, 0.00F),
new Vector3f(0.20F, 0.50F, 0.00F),
new Vector3f(0.30F, 0.55F, 0.00F),
new Vector3f(0.42F, 0.70F, 0.00F),
new Vector3f(0.50F, 1.00F, 0.00F)
);
ROOT = Lists.newArrayList(
new Vector3f(0F, 1F, 0),
new Vector3f(0.1F, 0.70F, 0),
new Vector3f(0.3F, 0.30F, 0),
new Vector3f(0.7F, 0.05F, 0),
new Vector3f(0.8F, -0.20F, 0)
);
SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0));
LEAF = Lists.newArrayList(
new Vector3f(0.00F, 0.0F, 0),
new Vector3f(0.10F, 0.4F, 0),
new Vector3f(0.40F, 0.8F, 0),
new Vector3f(0.75F, 0.9F, 0),
new Vector3f(1.00F, 0.8F, 0)
);
SIDE = Lists.newArrayList(
new Vector3f(0, -0.3F, -0.5F),
new Vector3f(0, -0.1F, -0.3F),
new Vector3f(0, 0.0F, 0.0F),
new Vector3f(0, -0.1F, 0.3F),
new Vector3f(0, -0.3F, 0.5F)
);
}
}