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,182 @@
package org.betterx.betterend.world.biome;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.api.surface.SurfaceRuleBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.bclib.world.biomes.BCLBiome;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.registry.EndTags;
public class EndBiome extends BCLBiome implements SurfaceMaterialProvider {
public static class DefaultSurfaceMaterialProvider implements SurfaceMaterialProvider {
public static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
@Override
public BlockState getTopMaterial() {
return getUnderMaterial();
}
@Override
public BlockState getAltTopMaterial() {
return getTopMaterial();
}
@Override
public BlockState getUnderMaterial() {
return END_STONE;
}
@Override
public boolean generateFloorRule() {
return true;
}
@Override
public SurfaceRuleBuilder surface() {
SurfaceRuleBuilder builder = SurfaceRuleBuilder.start();
if (generateFloorRule() && getTopMaterial() != getUnderMaterial()) {
if (getTopMaterial() != getAltTopMaterial()) {
builder.floor(getTopMaterial());
} else {
builder.chancedFloor(getTopMaterial(), getAltTopMaterial());
}
}
return builder.filler(getUnderMaterial());
}
}
public abstract static class Config {
public static final SurfaceMaterialProvider DEFAULT_MATERIAL = new DefaultSurfaceMaterialProvider();
protected static final SurfaceRules.RuleSource END_STONE = SurfaceRules.state(DefaultSurfaceMaterialProvider.END_STONE);
protected static final SurfaceRules.RuleSource END_MOSS = SurfaceRules.state(EndBlocks.END_MOSS.defaultBlockState());
protected static final SurfaceRules.RuleSource ENDSTONE_DUST = SurfaceRules.state(EndBlocks.ENDSTONE_DUST.defaultBlockState());
protected static final SurfaceRules.RuleSource END_MYCELIUM = SurfaceRules.state(EndBlocks.END_MYCELIUM.defaultBlockState());
protected static final SurfaceRules.RuleSource FLAVOLITE = SurfaceRules.state(EndBlocks.FLAVOLITE.stone.defaultBlockState());
protected static final SurfaceRules.RuleSource SULPHURIC_ROCK = SurfaceRules.state(EndBlocks.SULPHURIC_ROCK.stone.defaultBlockState());
protected static final SurfaceRules.RuleSource BRIMSTONE = SurfaceRules.state(EndBlocks.BRIMSTONE.defaultBlockState());
protected static final SurfaceRules.RuleSource PALLIDIUM_FULL = SurfaceRules.state(EndBlocks.PALLIDIUM_FULL.defaultBlockState());
protected static final SurfaceRules.RuleSource PALLIDIUM_HEAVY = SurfaceRules.state(EndBlocks.PALLIDIUM_HEAVY.defaultBlockState());
protected static final SurfaceRules.RuleSource PALLIDIUM_THIN = SurfaceRules.state(EndBlocks.PALLIDIUM_THIN.defaultBlockState());
protected static final SurfaceRules.RuleSource PALLIDIUM_TINY = SurfaceRules.state(EndBlocks.PALLIDIUM_TINY.defaultBlockState());
protected static final SurfaceRules.RuleSource UMBRALITH = SurfaceRules.state(EndBlocks.UMBRALITH.stone.defaultBlockState());
public final ResourceLocation ID;
protected Config(String name) {
this.ID = BetterEnd.makeID(name);
}
protected abstract void addCustomBuildData(BCLBiomeBuilder builder);
public BiomeSupplier<EndBiome> getSupplier() {
return EndBiome::new;
}
protected boolean hasCaves() {
return true;
}
protected SurfaceMaterialProvider surfaceMaterial() {
return DEFAULT_MATERIAL;
}
}
public EndBiome(ResourceLocation biomeID, Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
}
public static EndBiome create(Config biomeConfig) {
BCLBiomeBuilder builder = BCLBiomeBuilder
.start(biomeConfig.ID)
.music(SoundEvents.MUSIC_END)
.waterColor(4159204)
.waterFogColor(329011)
.fogColor(0xA080A0)
.skyColor(0)
.mood(EndSounds.AMBIENT_DUST_WASTELANDS)
.temperature(0.5f)
.wetness(0.5f)
.precipitation(Biome.Precipitation.NONE)
.surface(biomeConfig.surfaceMaterial().surface().build());
biomeConfig.addCustomBuildData(builder);
EndFeatures.addDefaultFeatures(builder, biomeConfig.hasCaves());
EndBiome biome = builder.build(biomeConfig.getSupplier());
biome.addCustomData("has_caves", biomeConfig.hasCaves());
biome.setSurfaceMaterial(biomeConfig.surfaceMaterial());
EndTags.addBiomeSurfaceToEndGroup(biome);
return biome;
}
private SurfaceMaterialProvider surfMatProv = Config.DEFAULT_MATERIAL;
private void setSurfaceMaterial(SurfaceMaterialProvider prov) {
surfMatProv = prov;
}
@Override
public BlockState getTopMaterial() {
return surfMatProv.getTopMaterial();
}
@Override
public BlockState getUnderMaterial() {
return surfMatProv.getUnderMaterial();
}
@Override
public BlockState getAltTopMaterial() {
return surfMatProv.getAltTopMaterial();
}
@Override
public boolean generateFloorRule() {
return surfMatProv.generateFloorRule();
}
@Override
public SurfaceRuleBuilder surface() {
return surfMatProv.surface();
}
public static BlockState findTopMaterial(BCLBiome biome) {
return BiomeAPI.findTopMaterial(biome).orElse(EndBiome.Config.DEFAULT_MATERIAL.getTopMaterial());
}
public static BlockState findTopMaterial(Biome biome) {
return findTopMaterial(BiomeAPI.getBiome(biome));
}
public static BlockState findTopMaterial(WorldGenLevel world, BlockPos pos) {
return findTopMaterial(BiomeAPI.getBiome(world.getBiome(pos)));
}
public static BlockState findUnderMaterial(BCLBiome biome) {
return BiomeAPI.findUnderMaterial(biome).orElse(EndBiome.Config.DEFAULT_MATERIAL.getUnderMaterial());
}
public static BlockState findUnderMaterial(WorldGenLevel world, BlockPos pos) {
return findUnderMaterial(BiomeAPI.getBiome(world.getBiome(pos)));
}
}

View file

@ -0,0 +1,34 @@
package org.betterx.betterend.world.biome.air;
import net.minecraft.world.entity.EntityType;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.registry.EndStructures;
import org.betterx.betterend.world.biome.EndBiome;
public class BiomeIceStarfield extends EndBiome.Config {
public BiomeIceStarfield() {
super("ice_starfield");
}
@Override
protected boolean hasCaves() {
return false;
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder.structure(EndStructures.GIANT_ICE_STAR)
.fogColor(224, 245, 254)
.temperature(0F)
.fogDensity(2.2F)
.foliageColor(193, 244, 244)
.genChance(0.25F)
.particles(EndParticles.SNOWFLAKE, 0.002F)
.feature(EndFeatures.ICE_STAR)
.feature(EndFeatures.ICE_STAR_SMALL)
.spawn(EntityType.ENDERMAN, 20, 1, 4);
}
}

View file

@ -0,0 +1,51 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.resources.ResourceLocation;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.world.biome.EndBiome;
public class EmptyAuroraCaveBiome extends EndCaveBiome.Config {
public static class Biome extends EndCaveBiome {
public Biome(ResourceLocation biomeID, net.minecraft.world.level.biome.Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
this.addFloorFeature(EndFeatures.BIG_AURORA_CRYSTAL, 1);
this.addCeilFeature(EndFeatures.END_STONE_STALACTITE, 1);
}
@Override
public float getFloorDensity() {
return 0.01F;
}
@Override
public float getCeilDensity() {
return 0.1F;
}
}
public EmptyAuroraCaveBiome() {
super("empty_aurora_cave");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
super.addCustomBuildData(builder);
builder.fogColor(150, 30, 68)
.fogDensity(2.0F)
.plantsColor(108, 25, 46)
.waterAndFogColor(186, 77, 237)
.particles(EndParticles.GLOWING_SPHERE, 0.001F);
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return EmptyAuroraCaveBiome.Biome::new;
}
}

View file

@ -0,0 +1,45 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.resources.ResourceLocation;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.world.biome.EndBiome;
public class EmptyEndCaveBiome extends EndCaveBiome.Config {
public static class Biome extends EndCaveBiome {
public Biome(ResourceLocation biomeID, net.minecraft.world.level.biome.Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
this.addFloorFeature(EndFeatures.END_STONE_STALAGMITE, 1);
this.addCeilFeature(EndFeatures.END_STONE_STALACTITE, 1);
}
@Override
public float getFloorDensity() {
return 0.1F;
}
@Override
public float getCeilDensity() {
return 0.1F;
}
}
public EmptyEndCaveBiome() {
super("empty_end_cave");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
super.addCustomBuildData(builder);
builder.fogDensity(2.0F);
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return Biome::new;
}
}

View file

@ -0,0 +1,52 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.resources.ResourceLocation;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.world.biome.EndBiome;
public class EmptySmaragdantCaveBiome extends EndCaveBiome.Config {
public static class Biome extends EndCaveBiome {
public Biome(ResourceLocation biomeID, net.minecraft.world.level.biome.Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
this.addFloorFeature(EndFeatures.SMARAGDANT_CRYSTAL, 1);
this.addFloorFeature(EndFeatures.SMARAGDANT_CRYSTAL_SHARD, 20);
this.addCeilFeature(EndFeatures.END_STONE_STALACTITE, 1);
}
@Override
public float getFloorDensity() {
return 0.1F;
}
@Override
public float getCeilDensity() {
return 0.1F;
}
}
public EmptySmaragdantCaveBiome() {
super("empty_smaragdant_cave");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
super.addCustomBuildData(builder);
builder.fogColor(0, 253, 182)
.fogDensity(2.0F)
.plantsColor(0, 131, 145)
.waterAndFogColor(31, 167, 212)
.particles(EndParticles.SMARAGDANT, 0.001F);
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return EmptySmaragdantCaveBiome.Biome::new;
}
}

View file

@ -0,0 +1,95 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.feature.Feature;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.api.features.BCLCommonFeatures;
import org.betterx.bclib.util.WeightedList;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.bclib.world.features.BCLFeature;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.features.terrain.caves.CaveChunkPopulatorFeature;
public class EndCaveBiome extends EndBiome {
public static abstract class Config extends EndBiome.Config {
protected Config(String name) {
super(name);
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
BCLFeature feature = BCLCommonFeatures.makeChunkFeature(
BetterEnd.makeID(ID.getPath() + "_cave_populator"),
GenerationStep.Decoration.RAW_GENERATION,
new CaveChunkPopulatorFeature(() -> (EndCaveBiome) BiomeAPI.getBiome(ID))
);
builder.feature(feature)
.music(EndSounds.MUSIC_CAVES)
.loop(EndSounds.AMBIENT_CAVES);
}
@Override
protected boolean hasCaves() {
return false;
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return EndCaveBiome::new;
}
}
private final WeightedList<Feature<?>> floorFeatures = new WeightedList<Feature<?>>();
private final WeightedList<Feature<?>> ceilFeatures = new WeightedList<Feature<?>>();
public EndCaveBiome(ResourceLocation biomeID, Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
}
public void addFloorFeature(Feature<?> feature, float weight) {
floorFeatures.add(feature, weight);
}
public void addCeilFeature(Feature<?> feature, float weight) {
ceilFeatures.add(feature, weight);
}
public Feature<?> getFloorFeature(RandomSource random) {
return floorFeatures.isEmpty() ? null : floorFeatures.get(random);
}
public Feature<?> getCeilFeature(RandomSource random) {
return ceilFeatures.isEmpty() ? null : ceilFeatures.get(random);
}
public float getFloorDensity() {
return 0;
}
public float getCeilDensity() {
return 0;
}
public BlockState getCeil(BlockPos pos) {
return null;
}
public BlockState getWall(BlockPos pos) {
return null;
}
public static EndCaveBiome create(EndBiome.Config biomeConfig) {
return (EndCaveBiome) EndBiome.create(biomeConfig);
}
}

View file

@ -0,0 +1,55 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.world.biome.EndBiome;
public class JadeCaveBiome extends EndCaveBiome.Config {
public static class Biome extends EndCaveBiome {
private static final OpenSimplexNoise WALL_NOISE = new OpenSimplexNoise("jade_cave".hashCode());
private static final OpenSimplexNoise DEPTH_NOISE = new OpenSimplexNoise("depth_noise".hashCode());
private static final BlockState[] JADE = new BlockState[3];
public Biome(ResourceLocation biomeID, net.minecraft.world.level.biome.Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
JADE[0] = EndBlocks.VIRID_JADESTONE.stone.defaultBlockState();
JADE[1] = EndBlocks.AZURE_JADESTONE.stone.defaultBlockState();
JADE[2] = EndBlocks.SANDY_JADESTONE.stone.defaultBlockState();
}
@Override
public BlockState getWall(BlockPos pos) {
double depth = DEPTH_NOISE.eval(pos.getX() * 0.02, pos.getZ() * 0.02) * 0.2 + 0.5;
int index = Mth.floor((pos.getY() + WALL_NOISE.eval(pos.getX() * 0.2,
pos.getZ() * 0.2) * 1.5) * depth + 0.5);
index = Mth.abs(index) % 3;
return JADE[index];
}
}
public JadeCaveBiome() {
super("jade_cave");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
super.addCustomBuildData(builder);
builder.fogColor(118, 150, 112)
.fogDensity(2.0F)
.waterAndFogColor(95, 223, 255);
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return JadeCaveBiome.Biome::new;
}
}

View file

@ -0,0 +1,80 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.world.biome.EndBiome;
public class LushAuroraCaveBiome extends EndCaveBiome.Config {
public static class Biome extends EndCaveBiome {
public Biome(ResourceLocation biomeID, net.minecraft.world.level.biome.Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
this.addFloorFeature(EndFeatures.BIG_AURORA_CRYSTAL, 1);
this.addFloorFeature(EndFeatures.CAVE_BUSH, 5);
this.addFloorFeature(EndFeatures.CAVE_GRASS, 40);
this.addFloorFeature(EndFeatures.END_STONE_STALAGMITE_CAVEMOSS, 5);
this.addCeilFeature(EndFeatures.CAVE_BUSH, 1);
this.addCeilFeature(EndFeatures.CAVE_PUMPKIN, 1);
this.addCeilFeature(EndFeatures.RUBINEA, 3);
this.addCeilFeature(EndFeatures.MAGNULA, 1);
this.addCeilFeature(EndFeatures.END_STONE_STALACTITE_CAVEMOSS, 10);
}
@Override
public float getFloorDensity() {
return 0.2F;
}
@Override
public float getCeilDensity() {
return 0.1F;
}
@Override
public BlockState getCeil(BlockPos pos) {
return EndBlocks.CAVE_MOSS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, BlockProperties.TripleShape.TOP);
}
}
public LushAuroraCaveBiome() {
super("lush_aurora_cave");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
super.addCustomBuildData(builder);
builder.fogColor(150, 30, 68)
.fogDensity(2.0F)
.plantsColor(108, 25, 46)
.waterAndFogColor(186, 77, 237)
.particles(EndParticles.GLOWING_SPHERE, 0.001F)
;
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return LushAuroraCaveBiome.Biome::new;
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.CAVE_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,65 @@
package org.betterx.betterend.world.biome.cave;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder.BiomeSupplier;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.world.biome.EndBiome;
public class LushSmaragdantCaveBiome extends EndCaveBiome.Config {
public static class Biome extends EndCaveBiome {
public Biome(ResourceLocation biomeID, net.minecraft.world.level.biome.Biome biome, BCLBiomeSettings settings) {
super(biomeID, biome, settings);
this.addFloorFeature(EndFeatures.SMARAGDANT_CRYSTAL, 1);
this.addFloorFeature(EndFeatures.SMARAGDANT_CRYSTAL_SHARD, 20);
this.addCeilFeature(EndFeatures.END_STONE_STALACTITE, 1);
}
@Override
public float getFloorDensity() {
return 0.1F;
}
@Override
public float getCeilDensity() {
return 0.1F;
}
}
public LushSmaragdantCaveBiome() {
super("lush_smaragdant_cave");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
super.addCustomBuildData(builder);
builder.fogColor(0, 253, 182)
.fogDensity(2.0F)
.plantsColor(0, 131, 145)
.waterAndFogColor(31, 167, 212)
.particles(EndParticles.SMARAGDANT, 0.001F);
}
@Override
public BiomeSupplier<EndBiome> getSupplier() {
return LushSmaragdantCaveBiome.Biome::new;
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.CAVE_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,52 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.*;
import org.betterx.betterend.world.biome.EndBiome;
public class AmberLandBiome extends EndBiome.Config {
public AmberLandBiome() {
super("amber_land");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(255, 184, 71)
.fogDensity(2.0F)
.plantsColor(219, 115, 38)
.waterAndFogColor(145, 108, 72)
.music(EndSounds.MUSIC_FOREST)
.loop(EndSounds.AMBIENT_AMBER_LAND)
.particles(EndParticles.AMBER_SPHERE, 0.001F)
.feature(EndFeatures.AMBER_ORE)
.feature(EndFeatures.END_LAKE_RARE)
.feature(EndFeatures.HELIX_TREE)
.feature(EndFeatures.LANCELEAF)
.feature(EndFeatures.GLOW_PILLAR)
.feature(EndFeatures.AMBER_GRASS)
.feature(EndFeatures.AMBER_ROOT)
.feature(EndFeatures.BULB_MOSS)
.feature(EndFeatures.BULB_MOSS_WOOD)
.feature(EndFeatures.CHARNIA_ORANGE)
.feature(EndFeatures.CHARNIA_RED)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 4)
.spawn(EndEntities.END_SLIME, 30, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.AMBER_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,56 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndEntities;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class BlossomingSpiresBiome extends EndBiome.Config {
public BlossomingSpiresBiome() {
super("blossoming_spires");
}
@Override
protected boolean hasCaves() {
return false;
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(241, 146, 229)
.fogDensity(1.7F)
.plantsColor(122, 45, 122)
.music(EndSounds.MUSIC_FOREST)
.loop(EndSounds.AMBIENT_BLOSSOMING_SPIRES)
.feature(EndFeatures.SPIRE)
.feature(EndFeatures.FLOATING_SPIRE)
.feature(EndFeatures.TENANEA)
.feature(EndFeatures.TENANEA_BUSH)
.feature(EndFeatures.BULB_VINE)
.feature(EndFeatures.BUSHY_GRASS)
.feature(EndFeatures.BUSHY_GRASS_WG)
.feature(EndFeatures.BLOSSOM_BERRY)
.feature(EndFeatures.TWISTED_MOSS)
.feature(EndFeatures.TWISTED_MOSS_WOOD)
.feature(EndFeatures.SILK_MOTH_NEST)
.spawn(EntityType.ENDERMAN, 50, 1, 4)
.spawn(EndEntities.SILK_MOTH, 5, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.PINK_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,59 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.data.worldgen.placement.EndPlacements;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndEntities;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class ChorusForestBiome extends EndBiome.Config {
public ChorusForestBiome() {
super("chorus_forest");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(87, 26, 87)
.fogDensity(1.5F)
.plantsColor(122, 45, 122)
.waterAndFogColor(73, 30, 73)
.particles(ParticleTypes.PORTAL, 0.01F)
.loop(EndSounds.AMBIENT_CHORUS_FOREST)
.music(EndSounds.MUSIC_DARK)
.feature(EndFeatures.VIOLECITE_LAYER)
.feature(EndFeatures.END_LAKE_RARE)
.feature(EndFeatures.PYTHADENDRON_TREE)
.feature(EndFeatures.PYTHADENDRON_BUSH)
.feature(EndFeatures.PURPLE_POLYPORE)
.feature(Decoration.VEGETAL_DECORATION, EndPlacements.CHORUS_PLANT)
.feature(EndFeatures.CHORUS_GRASS)
.feature(EndFeatures.CHORUS_MUSHROOM)
.feature(EndFeatures.TAIL_MOSS)
.feature(EndFeatures.TAIL_MOSS_WOOD)
.feature(EndFeatures.CHARNIA_PURPLE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EndEntities.END_SLIME, 5, 1, 2)
.spawn(EntityType.ENDERMAN, 50, 1, 4);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.CHORUS_NYLIUM.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,38 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.registry.EndStructures;
import org.betterx.betterend.world.biome.EndBiome;
public class CrystalMountainsBiome extends EndBiome.Config {
public CrystalMountainsBiome() {
super("crystal_mountains");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.structure(EndStructures.MOUNTAIN)
.plantsColor(255, 133, 211)
.music(EndSounds.MUSIC_OPENSPACE)
.feature(EndFeatures.CRYSTAL_GRASS)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.CRYSTAL_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,51 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class DragonGraveyardsBiome extends EndBiome.Config {
public DragonGraveyardsBiome() {
super("dragon_graveyards");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.genChance(0.1f)
.fogColor(244, 46, 79)
.fogDensity(1.3F)
.particles(EndParticles.FIREFLY, 0.0007F)
.music(EndSounds.MUSIC_OPENSPACE)
.loop(EndSounds.AMBIENT_GLOWING_GRASSLANDS)
.waterAndFogColor(203, 59, 167)
.plantsColor(244, 46, 79)
.feature(EndFeatures.OBSIDIAN_PILLAR_BASEMENT)
.feature(EndFeatures.DRAGON_BONE_BLOCK_ORE)
.feature(EndFeatures.FALLEN_PILLAR)
.feature(EndFeatures.OBSIDIAN_BOULDER)
.feature(EndFeatures.GIGANTIC_AMARANITA)
.feature(EndFeatures.LARGE_AMARANITA)
.feature(EndFeatures.SMALL_AMARANITA)
.feature(EndFeatures.GLOBULAGUS)
.feature(EndFeatures.CLAWFERN)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.SANGNUM.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,45 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class DryShrublandBiome extends EndBiome.Config {
public DryShrublandBiome() {
super("dry_shrubland");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(132, 35, 13)
.fogDensity(1.2F)
.waterAndFogColor(113, 88, 53)
.plantsColor(237, 122, 66)
.music(EndSounds.MUSIC_OPENSPACE)
.feature(EndFeatures.LUCERNIA_BUSH_RARE)
.feature(EndFeatures.ORANGO)
.feature(EndFeatures.AERIDIUM)
.feature(EndFeatures.LUTEBUS)
.feature(EndFeatures.LAMELLARIUM)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.RUTISCUS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,56 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import net.minecraft.world.level.levelgen.placement.CaveSurface;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.surface.SurfaceRuleBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class DustWastelandsBiome extends EndBiome.Config {
public DustWastelandsBiome() {
super("dust_wastelands");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(226, 239, 168)
.fogDensity(2)
.waterAndFogColor(192, 180, 131)
.terrainHeight(1.5F)
.particles(ParticleTypes.WHITE_ASH, 0.01F)
.loop(EndSounds.AMBIENT_DUST_WASTELANDS)
.music(EndSounds.MUSIC_OPENSPACE)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
@Override
public SurfaceRuleBuilder surface() {
return super
.surface()
.ceil(Blocks.END_STONE.defaultBlockState())
.rule(4, SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(5, false, CaveSurface.FLOOR),
SurfaceRules.state(EndBlocks.ENDSTONE_DUST.defaultBlockState())
));
}
};
}
}

View file

@ -0,0 +1,66 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.*;
import org.betterx.betterend.world.biome.EndBiome;
public class FoggyMushroomlandBiome extends EndBiome.Config {
public FoggyMushroomlandBiome() {
super("foggy_mushroomland");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.structure(EndStructures.GIANT_MOSSY_GLOWSHROOM)
.plantsColor(73, 210, 209)
.fogColor(41, 122, 173)
.fogDensity(3)
.waterAndFogColor(119, 227, 250)
.particles(EndParticles.GLOWING_SPHERE, 0.001F)
.loop(EndSounds.AMBIENT_FOGGY_MUSHROOMLAND)
.music(EndSounds.MUSIC_FOREST)
.feature(EndFeatures.END_LAKE)
.feature(EndFeatures.MOSSY_GLOWSHROOM)
.feature(EndFeatures.BLUE_VINE)
.feature(EndFeatures.UMBRELLA_MOSS)
.feature(EndFeatures.CREEPING_MOSS)
.feature(EndFeatures.DENSE_VINE)
//.feature(EndFeatures.PEARLBERRY)
.feature(EndFeatures.CYAN_MOSS)
.feature(EndFeatures.CYAN_MOSS_WOOD)
.feature(EndFeatures.END_LILY)
.feature(EndFeatures.BUBBLE_CORAL)
.feature(EndFeatures.CHARNIA_CYAN)
.feature(EndFeatures.CHARNIA_LIGHT_BLUE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EndEntities.DRAGONFLY, 80, 2, 5)
.spawn(EndEntities.END_FISH, 20, 2, 5)
.spawn(EndEntities.CUBOZOA, 10, 3, 8)
.spawn(EndEntities.END_SLIME, 10, 1, 2)
.spawn(EntityType.ENDERMAN, 10, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.END_MOSS.defaultBlockState();
}
@Override
public BlockState getAltTopMaterial() {
return EndBlocks.END_MYCELIUM.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,56 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class GlowingGrasslandsBiome extends EndBiome.Config {
public GlowingGrasslandsBiome() {
super("glowing_grasslands");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(99, 228, 247)
.fogDensity(1.3F)
.particles(EndParticles.FIREFLY, 0.001F)
.music(EndSounds.MUSIC_OPENSPACE)
.loop(EndSounds.AMBIENT_GLOWING_GRASSLANDS)
.waterAndFogColor(92, 250, 230)
.plantsColor(73, 210, 209)
.feature(EndFeatures.END_LAKE_RARE)
.feature(EndFeatures.LUMECORN)
.feature(EndFeatures.BLOOMING_COOKSONIA)
.feature(EndFeatures.SALTEAGO)
.feature(EndFeatures.VAIOLUSH_FERN)
.feature(EndFeatures.FRACTURN)
.feature(EndFeatures.UMBRELLA_MOSS_RARE)
.feature(EndFeatures.CREEPING_MOSS_RARE)
.feature(EndFeatures.TWISTED_UMBRELLA_MOSS_RARE)
.feature(EndFeatures.CHARNIA_CYAN)
.feature(EndFeatures.CHARNIA_GREEN)
.feature(EndFeatures.CHARNIA_LIGHT_BLUE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.END_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,56 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class LanternWoodsBiome extends EndBiome.Config {
public LanternWoodsBiome() {
super("lantern_woods");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(189, 82, 70)
.fogDensity(1.1F)
.waterAndFogColor(171, 234, 226)
.plantsColor(254, 85, 57)
.music(EndSounds.MUSIC_FOREST)
.particles(EndParticles.GLOWING_SPHERE, 0.001F)
.feature(EndFeatures.END_LAKE_NORMAL)
.feature(EndFeatures.FLAMAEA)
.feature(EndFeatures.LUCERNIA)
.feature(EndFeatures.LUCERNIA_BUSH)
.feature(EndFeatures.FILALUX)
.feature(EndFeatures.AERIDIUM)
.feature(EndFeatures.LAMELLARIUM)
.feature(EndFeatures.BOLUX_MUSHROOM)
.feature(EndFeatures.AURANT_POLYPORE)
.feature(EndFeatures.POND_ANEMONE)
.feature(EndFeatures.CHARNIA_ORANGE)
.feature(EndFeatures.CHARNIA_RED)
.feature(EndFeatures.RUSCUS)
.feature(EndFeatures.RUSCUS_WOOD)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.RUTISCUS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,59 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.*;
import org.betterx.betterend.world.biome.EndBiome;
public class MegalakeBiome extends EndBiome.Config {
public MegalakeBiome() {
super("megalake");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.structure(EndStructures.MEGALAKE)
.plantsColor(73, 210, 209)
.fogColor(178, 209, 248)
.waterAndFogColor(96, 163, 255)
.fogDensity(1.75F)
.music(EndSounds.MUSIC_WATER)
.loop(EndSounds.AMBIENT_MEGALAKE)
.terrainHeight(0F)
.feature(EndFeatures.END_LOTUS)
.feature(EndFeatures.END_LOTUS_LEAF)
.feature(EndFeatures.BUBBLE_CORAL_RARE)
.feature(EndFeatures.END_LILY_RARE)
.feature(EndFeatures.UMBRELLA_MOSS)
.feature(EndFeatures.CREEPING_MOSS)
//.feature(EndFeatures.PEARLBERRY)
.feature(EndFeatures.CHARNIA_CYAN)
.feature(EndFeatures.CHARNIA_LIGHT_BLUE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.feature(EndFeatures.MENGER_SPONGE)
.spawn(EndEntities.DRAGONFLY, 50, 1, 3)
.spawn(EndEntities.END_FISH, 50, 3, 8)
.spawn(EndEntities.CUBOZOA, 50, 3, 8)
.spawn(EndEntities.END_SLIME, 5, 1, 2)
.spawn(EntityType.ENDERMAN, 10, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.END_MOSS.defaultBlockState();
}
@Override
public BlockState getAltTopMaterial() {
return EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,56 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.*;
import org.betterx.betterend.world.biome.EndBiome;
public class MegalakeGroveBiome extends EndBiome.Config {
public MegalakeGroveBiome() {
super("megalake_grove");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.structure(EndStructures.MEGALAKE_SMALL)
.plantsColor(73, 210, 209)
.fogColor(178, 209, 248)
.waterAndFogColor(96, 163, 255)
.fogDensity(2.0F)
.particles(EndParticles.GLOWING_SPHERE, 0.001F)
.music(EndSounds.MUSIC_WATER)
.loop(EndSounds.AMBIENT_MEGALAKE_GROVE)
.terrainHeight(0F)
.feature(EndFeatures.LACUGROVE)
.feature(EndFeatures.END_LOTUS)
.feature(EndFeatures.END_LOTUS_LEAF)
.feature(EndFeatures.BUBBLE_CORAL_RARE)
.feature(EndFeatures.END_LILY_RARE)
.feature(EndFeatures.UMBRELLA_MOSS)
//.feature(EndFeatures.PEARLBERRY)
.feature(EndFeatures.CREEPING_MOSS)
.feature(EndFeatures.CHARNIA_CYAN)
.feature(EndFeatures.CHARNIA_LIGHT_BLUE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.feature(EndFeatures.MENGER_SPONGE)
.spawn(EndEntities.DRAGONFLY, 20, 1, 3)
.spawn(EndEntities.END_FISH, 20, 3, 8)
.spawn(EndEntities.CUBOZOA, 50, 3, 8)
.spawn(EndEntities.END_SLIME, 5, 1, 2)
.spawn(EntityType.ENDERMAN, 10, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.END_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,82 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
import net.minecraft.world.level.levelgen.placement.CaveSurface;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.surface.SurfaceRuleBuilder;
import org.betterx.bclib.api.surface.rules.SwitchRuleSource;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.surface.SplitNoiseCondition;
import java.util.List;
public class NeonOasisBiome extends EndBiome.Config {
public NeonOasisBiome() {
super("neon_oasis");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.genChance(0.5F)
.fogColor(226, 239, 168)
.fogDensity(2)
.waterAndFogColor(106, 238, 215)
.particles(ParticleTypes.WHITE_ASH, 0.01F)
.loop(EndSounds.AMBIENT_DUST_WASTELANDS)
.music(EndSounds.MUSIC_OPENSPACE)
.feature(EndFeatures.DESERT_LAKE)
.feature(EndFeatures.NEON_CACTUS)
.feature(EndFeatures.UMBRELLA_MOSS)
.feature(EndFeatures.CREEPING_MOSS)
.feature(EndFeatures.CHARNIA_GREEN)
.feature(EndFeatures.CHARNIA_CYAN)
.feature(EndFeatures.CHARNIA_RED)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
@Override
public BlockState getAltTopMaterial() {
return EndBlocks.END_MOSS.defaultBlockState();
}
@Override
public SurfaceRuleBuilder surface() {
RuleSource surfaceBlockRule = new SwitchRuleSource(
new SplitNoiseCondition(),
List.of(
SurfaceRules.state(EndBlocks.ENDSTONE_DUST.defaultBlockState()),
SurfaceRules.state(EndBlocks.END_MOSS.defaultBlockState())
)
);
return super
.surface()
.ceil(Blocks.END_STONE.defaultBlockState())
.rule(1, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, surfaceBlockRule))
.rule(4, SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(5, false, CaveSurface.FLOOR),
SurfaceRules.state(EndBlocks.ENDSTONE_DUST.defaultBlockState())
));
}
};
}
}

View file

@ -0,0 +1,41 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.registry.EndStructures;
import org.betterx.betterend.world.biome.EndBiome;
public class PaintedMountainsBiome extends EndBiome.Config {
public PaintedMountainsBiome() {
super("painted_mountains");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.structure(EndStructures.PAINTED_MOUNTAIN)
.fogColor(226, 239, 168)
.fogDensity(2)
.waterAndFogColor(192, 180, 131)
.music(EndSounds.MUSIC_OPENSPACE)
.loop(EndSounds.AMBIENT_DUST_WASTELANDS)
.particles(ParticleTypes.WHITE_ASH, 0.01F)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.ENDSTONE_DUST.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,60 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndEntities;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class ShadowForestBiome extends EndBiome.Config {
public ShadowForestBiome() {
super("shadow_forest");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(0, 0, 0)
.fogDensity(2.5F)
.plantsColor(45, 45, 45)
.waterAndFogColor(42, 45, 80)
.particles(ParticleTypes.MYCELIUM, 0.01F)
.loop(EndSounds.AMBIENT_CHORUS_FOREST)
.music(EndSounds.MUSIC_DARK)
.feature(EndFeatures.VIOLECITE_LAYER)
.feature(EndFeatures.END_LAKE_RARE)
.feature(EndFeatures.DRAGON_TREE)
.feature(EndFeatures.DRAGON_TREE_BUSH)
.feature(EndFeatures.SHADOW_PLANT)
.feature(EndFeatures.MURKWEED)
.feature(EndFeatures.NEEDLEGRASS)
.feature(EndFeatures.SHADOW_BERRY)
.feature(EndFeatures.TWISTED_VINE)
.feature(EndFeatures.PURPLE_POLYPORE)
.feature(EndFeatures.TAIL_MOSS)
.feature(EndFeatures.TAIL_MOSS_WOOD)
.feature(EndFeatures.CHARNIA_PURPLE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EndEntities.SHADOW_WALKER, 80, 2, 4)
.spawn(EntityType.ENDERMAN, 40, 1, 4)
.spawn(EntityType.PHANTOM, 1, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.SHADOW_GRASS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,92 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
import net.minecraft.world.level.levelgen.placement.CaveSurface;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.surface.SurfaceRuleBuilder;
import org.betterx.bclib.api.surface.rules.SwitchRuleSource;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.*;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.surface.SulphuricSurfaceNoiseCondition;
import java.util.List;
public class SulphurSpringsBiome extends EndBiome.Config {
public SulphurSpringsBiome() {
super("sulphur_springs");
}
@Override
protected boolean hasCaves() {
return false;
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.music(EndSounds.MUSIC_OPENSPACE)
.loop(EndSounds.AMBIENT_SULPHUR_SPRINGS)
.waterColor(25, 90, 157)
.waterFogColor(30, 65, 61)
.fogColor(207, 194, 62)
.fogDensity(1.5F)
.terrainHeight(0F)
.particles(EndParticles.SULPHUR_PARTICLE, 0.001F)
.feature(EndFeatures.GEYSER)
.feature(EndFeatures.SURFACE_VENT)
.feature(EndFeatures.SULPHURIC_LAKE)
.feature(EndFeatures.SULPHURIC_CAVE)
.feature(EndFeatures.HYDRALUX)
.feature(EndFeatures.CHARNIA_GREEN)
.feature(EndFeatures.CHARNIA_ORANGE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.spawn(EndEntities.END_FISH, 50, 3, 8)
.spawn(EndEntities.CUBOZOA, 50, 3, 8)
.spawn(EntityType.ENDERMAN, 50, 1, 4);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.FLAVOLITE.stone.defaultBlockState();
}
@Override
public BlockState getAltTopMaterial() {
return Blocks.END_STONE.defaultBlockState();
}
@Override
public boolean generateFloorRule() {
return false;
}
@Override
public SurfaceRuleBuilder surface() {
RuleSource surfaceBlockRule = new SwitchRuleSource(
new SulphuricSurfaceNoiseCondition(),
List.of(
SurfaceRules.state(surfaceMaterial().getAltTopMaterial()),
SurfaceRules.state(surfaceMaterial().getTopMaterial()),
SULPHURIC_ROCK,
BRIMSTONE
)
);
return super
.surface()
.rule(2, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, surfaceBlockRule))
.rule(2,
SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(5, false, CaveSurface.FLOOR),
surfaceBlockRule));
}
};
}
}

View file

@ -0,0 +1,93 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.SurfaceRules;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.surface.SurfaceRuleBuilder;
import org.betterx.bclib.api.surface.rules.SwitchRuleSource;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.surface.UmbraSurfaceNoiseCondition;
import java.util.List;
public class UmbraValleyBiome extends EndBiome.Config {
private static final Block[] SURFACE_BLOCKS = new Block[]{
EndBlocks.PALLIDIUM_FULL,
EndBlocks.PALLIDIUM_HEAVY,
EndBlocks.PALLIDIUM_THIN,
EndBlocks.PALLIDIUM_TINY,
EndBlocks.UMBRALITH.stone
};
public UmbraValleyBiome() {
super("umbra_valley");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(100, 100, 100)
.plantsColor(172, 189, 190)
.waterAndFogColor(69, 104, 134)
.particles(EndParticles.AMBER_SPHERE, 0.0001F)
.loop(EndSounds.UMBRA_VALLEY)
.music(EndSounds.MUSIC_DARK)
.feature(EndFeatures.UMBRALITH_ARCH)
.feature(EndFeatures.THIN_UMBRALITH_ARCH)
.feature(EndFeatures.INFLEXIA)
.feature(EndFeatures.FLAMMALIX);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.UMBRALITH.stone.defaultBlockState();
}
@Override
public BlockState getUnderMaterial() {
return EndBlocks.UMBRALITH.stone.defaultBlockState();
}
@Override
public BlockState getAltTopMaterial() {
return EndBlocks.PALLIDIUM_FULL.defaultBlockState();
}
@Override
public boolean generateFloorRule() {
return false;
}
@Override
public SurfaceRuleBuilder surface() {
return super.surface()
.rule(2, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR,
new SwitchRuleSource(
new UmbraSurfaceNoiseCondition(),
List.of(
SurfaceRules.state(surfaceMaterial().getAltTopMaterial()),
PALLIDIUM_HEAVY,
PALLIDIUM_THIN,
PALLIDIUM_TINY,
SurfaceRules.state(surfaceMaterial().getTopMaterial())
)
)
));
}
};
}
public static Block getSurface(int x, int z) {
return SURFACE_BLOCKS[UmbraSurfaceNoiseCondition.getDepth(x, z)];
}
}

View file

@ -0,0 +1,60 @@
package org.betterx.betterend.world.biome.land;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.api.biomes.BCLBiomeBuilder;
import org.betterx.bclib.interfaces.SurfaceMaterialProvider;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndParticles;
import org.betterx.betterend.registry.EndSounds;
import org.betterx.betterend.world.biome.EndBiome;
public class UmbrellaJungleBiome extends EndBiome.Config {
public UmbrellaJungleBiome() {
super("umbrella_jungle");
}
@Override
protected void addCustomBuildData(BCLBiomeBuilder builder) {
builder
.fogColor(87, 223, 221)
.waterAndFogColor(119, 198, 253)
.foliageColor(27, 183, 194)
.fogDensity(2.3F)
.particles(EndParticles.JUNGLE_SPORE, 0.001F)
.music(EndSounds.MUSIC_FOREST)
.loop(EndSounds.AMBIENT_UMBRELLA_JUNGLE)
.feature(EndFeatures.END_LAKE)
.feature(EndFeatures.UMBRELLA_TREE)
.feature(EndFeatures.JELLYSHROOM)
.feature(EndFeatures.TWISTED_UMBRELLA_MOSS)
.feature(EndFeatures.SMALL_JELLYSHROOM_FLOOR)
.feature(EndFeatures.JUNGLE_GRASS)
.feature(EndFeatures.CYAN_MOSS)
.feature(EndFeatures.CYAN_MOSS_WOOD)
.feature(EndFeatures.JUNGLE_FERN_WOOD)
.feature(EndFeatures.SMALL_JELLYSHROOM_WALL)
.feature(EndFeatures.SMALL_JELLYSHROOM_WOOD)
.feature(EndFeatures.SMALL_JELLYSHROOM_CEIL)
.feature(EndFeatures.JUNGLE_VINE)
.feature(EndFeatures.CHARNIA_CYAN)
.feature(EndFeatures.CHARNIA_GREEN)
.feature(EndFeatures.CHARNIA_LIGHT_BLUE)
.feature(EndFeatures.CHARNIA_RED_RARE)
.structure(BiomeTags.HAS_END_CITY)
.spawn(EntityType.ENDERMAN, 50, 1, 2);
}
@Override
protected SurfaceMaterialProvider surfaceMaterial() {
return new EndBiome.DefaultSurfaceMaterialProvider() {
@Override
public BlockState getTopMaterial() {
return EndBlocks.JUNGLE_MOSS.defaultBlockState();
}
};
}
}

View file

@ -0,0 +1,73 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
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 org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFDisplacement;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.world.biome.EndBiome;
public class BiomeIslandFeature extends DefaultFeature {
private static final MutableBlockPos CENTER = new MutableBlockPos();
private static final SDF ISLAND;
private static OpenSimplexNoise simplexNoise = new OpenSimplexNoise(412L);
private static BlockState topBlock = Blocks.GRASS_BLOCK.defaultBlockState();
private static BlockState underBlock = Blocks.DIRT.defaultBlockState();
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
//Holder<Biome> biome = world.getBiome(pos);
int dist = BlocksHelper.downRay(world, pos, 10) + 1;
BlockPos surfacePos = new BlockPos(pos.getX(), pos.getY() - dist, pos.getZ());
BlockState topMaterial = EndBiome.findTopMaterial(world, surfacePos);
if (BlocksHelper.isFluid(topMaterial)) {
topBlock = Blocks.GRAVEL.defaultBlockState();
underBlock = Blocks.STONE.defaultBlockState();
} else {
underBlock = EndBiome.findUnderMaterial(world, surfacePos);
}
simplexNoise = new OpenSimplexNoise(world.getSeed());
CENTER.set(pos);
ISLAND.fillRecursive(world, pos.below());
return true;
}
private static SDF createSDFIsland() {
SDF sdfCone = new SDFCappedCone().setRadius1(0).setRadius2(6).setHeight(4).setBlock(pos -> {
if (pos.getY() > CENTER.getY()) return AIR;
if (pos.getY() == CENTER.getY()) return topBlock;
return underBlock;
});
sdfCone = new SDFTranslate().setTranslate(0, -2, 0).setSource(sdfCone);
sdfCone = new SDFDisplacement().setFunction(pos -> {
float deltaX = Math.abs(pos.x());
float deltaY = Math.abs(pos.y());
float deltaZ = Math.abs(pos.z());
if (deltaY < 2.0f && (deltaX < 3.0f || deltaZ < 3.0F)) return 0.0f;
return (float) simplexNoise.eval(CENTER.getX() + pos.x(), CENTER.getY() + pos.y(), CENTER.getZ() + pos.z());
})
.setSource(sdfCone)
.setReplaceFunction(state -> BlocksHelper.isFluid(state) || state.getMaterial()
.isReplaceable());
return sdfCone;
}
static {
ISLAND = createSDFIsland();
}
}

View file

@ -0,0 +1,47 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.betterend.blocks.basis.EndPlantWithAgeBlock;
import org.betterx.betterend.registry.EndBlocks;
public class BlueVineFeature extends ScatterFeature {
private boolean small;
public BlueVineFeature() {
super(5);
}
@Override
@SuppressWarnings("deprecation")
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
float d = MHelper.length(
center.getX() - blockPos.getX(),
center.getZ() - blockPos.getZ()
) / radius * 0.6F + random.nextFloat() * 0.4F;
small = d > 0.5F;
return EndBlocks.BLUE_VINE_SEED.canSurvive(AIR, world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
if (small) {
BlocksHelper.setWithoutUpdate(
world,
blockPos,
EndBlocks.BLUE_VINE_SEED.defaultBlockState().setValue(EndPlantWithAgeBlock.AGE, random.nextInt(4))
);
} else {
EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.BLUE_VINE_SEED);
seed.growAdult(world, random, blockPos);
}
}
}

View file

@ -0,0 +1,68 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
import org.betterx.bclib.world.features.ListFeature;
import org.betterx.betterend.util.LootTableUtil;
import java.util.List;
import org.jetbrains.annotations.Nullable;
public class BuildingListFeature extends ListFeature {
public BuildingListFeature(List<StructureInfo> list, BlockState defaultBlock) {
super(list, defaultBlock);
}
@Override
protected void addStructureData(StructurePlaceSettings data) {
super.addStructureData(data);
data.addProcessor(new ChestProcessor());
}
class ChestProcessor extends StructureProcessor {
@Nullable
@Override
public StructureTemplate.StructureBlockInfo processBlock(LevelReader levelReader,
BlockPos blockPos,
BlockPos blockPos2,
StructureBlockInfo structureBlockInfo,
StructureBlockInfo structureBlockInfo2,
StructurePlaceSettings structurePlaceSettings) {
BlockState blockState = structureBlockInfo2.state;
if (blockState.getBlock() instanceof ChestBlock) {
RandomSource random = structurePlaceSettings.getRandom(structureBlockInfo2.pos);
BlockPos chestPos = structureBlockInfo2.pos;
ChestBlock chestBlock = (ChestBlock) blockState.getBlock();
BlockEntity entity = chestBlock.newBlockEntity(chestPos, blockState);
levelReader.getChunk(chestPos).setBlockEntity(entity);
RandomizableContainerBlockEntity chestEntity = (RandomizableContainerBlockEntity) entity;
Holder<Biome> biome = levelReader.getNoiseBiome(
chestPos.getX() >> 2,
chestPos.getY() >> 2,
chestPos.getZ() >> 2
);
chestEntity.setLootTable(LootTableUtil.getTable(biome), random.nextLong());
chestEntity.setChanged();
}
return structureBlockInfo2;
}
@Override
protected StructureProcessorType<?> getType() {
return StructureProcessorType.NOP;
}
}
}

View file

@ -0,0 +1,43 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.EndBlockProperties;
import org.betterx.betterend.registry.EndBlocks;
public class CavePumpkinFeature 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.above())
.is(CommonBlockTags.GEN_END_STONES) || !world.isEmptyBlock(pos) || !world.isEmptyBlock(
pos.below())) {
return false;
}
int age = random.nextInt(4);
BlocksHelper.setWithoutUpdate(
world,
pos,
EndBlocks.CAVE_PUMPKIN_SEED.defaultBlockState().setValue(EndBlockProperties.AGE, age)
);
if (age > 1) {
BlocksHelper.setWithoutUpdate(
world,
pos.below(),
EndBlocks.CAVE_PUMPKIN.defaultBlockState().setValue(EndBlockProperties.SMALL, age < 3)
);
}
return true;
}
}

View file

@ -0,0 +1,14 @@
package org.betterx.betterend.world.features;
import net.minecraft.world.level.block.Block;
public class CharniaFeature extends UnderwaterPlantFeature {
public CharniaFeature(Block plant) {
super(plant, 6);
}
@Override
protected int getChance() {
return 3;
}
}

View file

@ -0,0 +1,148 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
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.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.*;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
import net.minecraft.world.level.material.Material;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.util.StructureHelper;
import org.betterx.bclib.world.features.NBTFeature;
import org.betterx.betterend.util.BlockFixer;
import org.betterx.betterend.util.StructureErode;
import org.betterx.betterend.world.biome.EndBiome;
public class CrashedShipFeature extends NBTFeature {
private static final StructureProcessor REPLACER;
private static final String STRUCTURE_PATH = "/data/minecraft/structures/end_city/ship.nbt";
private StructureTemplate structure;
public CrashedShipFeature() {
super(EndBiome.Config.DEFAULT_MATERIAL.getTopMaterial());
}
@Override
protected StructureTemplate getStructure(WorldGenLevel world, BlockPos pos, RandomSource random) {
if (structure == null) {
structure = world.getLevel().getStructureManager().getOrCreate(new ResourceLocation("end_city/ship"));
if (structure == null) {
structure = StructureHelper.readStructure(STRUCTURE_PATH);
}
}
return structure;
}
@Override
protected boolean canSpawn(WorldGenLevel world, BlockPos pos, RandomSource random) {
long x = pos.getX() >> 4;
long z = pos.getX() >> 4;
if (x * x + z * z < 3600) {
return false;
}
return pos.getY() > 5 && world.getBlockState(pos.below()).is(CommonBlockTags.GEN_END_STONES);
}
@Override
protected Rotation getRotation(WorldGenLevel world, BlockPos pos, RandomSource random) {
return Rotation.getRandom(random);
}
@Override
protected Mirror getMirror(WorldGenLevel world, BlockPos pos, RandomSource random) {
return Mirror.values()[random.nextInt(3)];
}
@Override
protected int getYOffset(StructureTemplate structure, WorldGenLevel world, BlockPos pos, RandomSource random) {
int min = structure.getSize().getY() >> 3;
int max = structure.getSize().getY() >> 2;
return -MHelper.randRange(min, max, random);
}
@Override
protected TerrainMerge getTerrainMerge(WorldGenLevel world, BlockPos pos, RandomSource random) {
return TerrainMerge.NONE;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos center = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8);
center = getGround(world, center);
BoundingBox bounds = makeBox(center);
if (!canSpawn(world, center, random)) {
return false;
}
StructureTemplate structure = getStructure(world, center, random);
Rotation rotation = getRotation(world, center, random);
Mirror mirror = getMirror(world, center, random);
BlockPos offset = StructureTemplate.transform(
new BlockPos(structure.getSize()),
mirror,
rotation,
BlockPos.ZERO
);
center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror);
center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5);
BoundingBox structB = structure.getBoundingBox(placementData, center);
bounds = StructureHelper.intersectBoxes(bounds, structB);
addStructureData(placementData);
structure.placeInWorld(world, center, center, placementData.setBoundingBox(bounds), random, 2);
StructureErode.erodeIntense(world, bounds, random);
BlockFixer.fixBlocks(
world,
new BlockPos(bounds.minX(), bounds.minY(), bounds.minZ()),
new BlockPos(bounds.maxX(), bounds.maxY(), bounds.maxZ())
);
return true;
}
@Override
protected void addStructureData(StructurePlaceSettings data) {
data.addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR).addProcessor(REPLACER).setIgnoreEntities(true);
}
static {
REPLACER = new StructureProcessor() {
@Override
public StructureBlockInfo processBlock(LevelReader worldView,
BlockPos pos,
BlockPos blockPos,
StructureBlockInfo structureBlockInfo,
StructureBlockInfo structureBlockInfo2,
StructurePlaceSettings structurePlacementData) {
BlockState state = structureBlockInfo2.state;
if (state.is(Blocks.SPAWNER) || state.getMaterial().equals(Material.WOOL)) {
return new StructureBlockInfo(structureBlockInfo2.pos, AIR, null);
}
return structureBlockInfo2;
}
@Override
protected StructureProcessorType<?> getType() {
return StructureProcessorType.NOP;
}
};
}
}

View file

@ -0,0 +1,49 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.blocks.BaseDoublePlantBlock;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
public class DoublePlantFeature extends ScatterFeature {
private final Block smallPlant;
private final Block largePlant;
private Block plant;
public DoublePlantFeature(Block smallPlant, Block largePlant, int radius) {
super(radius);
this.smallPlant = smallPlant;
this.largePlant = largePlant;
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
float d = MHelper.length(
center.getX() - blockPos.getX(),
center.getZ() - blockPos.getZ()
) / radius * 0.6F + random.nextFloat() * 0.4F;
plant = d < 0.5F ? largePlant : smallPlant;
return plant.canSurvive(plant.defaultBlockState(), world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
if (plant instanceof BaseDoublePlantBlock) {
int rot = random.nextInt(4);
BlockState state = plant.defaultBlockState().setValue(BaseDoublePlantBlock.ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, blockPos, state);
BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(BaseDoublePlantBlock.TOP, true));
} else {
BlocksHelper.setWithoutUpdate(world, blockPos, plant);
}
}
}

View file

@ -0,0 +1,25 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import org.betterx.betterend.blocks.EndLilySeedBlock;
import org.betterx.betterend.registry.EndBlocks;
public class EndLilyFeature extends UnderwaterPlantScatter {
public EndLilyFeature(int radius) {
super(radius);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
EndLilySeedBlock seed = (EndLilySeedBlock) EndBlocks.END_LILY_SEED;
seed.grow(world, random, blockPos);
}
@Override
protected int getChance() {
return 15;
}
}

View file

@ -0,0 +1,25 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import org.betterx.betterend.blocks.EndLotusSeedBlock;
import org.betterx.betterend.registry.EndBlocks;
public class EndLotusFeature extends UnderwaterPlantScatter {
public EndLotusFeature(int radius) {
super(radius);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
EndLotusSeedBlock seed = (EndLotusSeedBlock) EndBlocks.END_LOTUS_SEED;
seed.grow(world, random, blockPos);
}
@Override
protected int getChance() {
return 15;
}
}

View file

@ -0,0 +1,84 @@
package org.betterx.betterend.world.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.state.BlockState;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.betterend.blocks.EndLotusLeafBlock;
import org.betterx.betterend.registry.EndBlocks;
public class EndLotusLeafFeature extends ScatterFeature {
public EndLotusLeafFeature(int radius) {
super(radius);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
if (canGenerate(world, blockPos)) {
generateLeaf(world, blockPos);
}
}
@Override
protected int getChance() {
return 15;
}
@Override
protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) {
return getPosOnSurface(world, pos);
}
private void generateLeaf(WorldGenLevel world, BlockPos pos) {
MutableBlockPos p = new MutableBlockPos();
BlockState leaf = EndBlocks.END_LOTUS_LEAF.defaultBlockState();
BlocksHelper.setWithoutUpdate(world, pos, leaf.setValue(EndLotusLeafBlock.SHAPE, TripleShape.BOTTOM));
for (Direction move : BlocksHelper.HORIZONTAL) {
BlocksHelper.setWithoutUpdate(
world,
p.set(pos).move(move),
leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, move)
.setValue(EndLotusLeafBlock.SHAPE, TripleShape.MIDDLE)
);
}
for (int i = 0; i < 4; i++) {
Direction d1 = BlocksHelper.HORIZONTAL[i];
Direction d2 = BlocksHelper.HORIZONTAL[(i + 1) & 3];
BlocksHelper.setWithoutUpdate(
world,
p.set(pos).move(d1).move(d2),
leaf.setValue(EndLotusLeafBlock.HORIZONTAL_FACING, d1)
.setValue(EndLotusLeafBlock.SHAPE, TripleShape.TOP)
);
}
}
private boolean canGenerate(WorldGenLevel world, BlockPos pos) {
MutableBlockPos p = new MutableBlockPos();
p.setY(pos.getY());
int count = 0;
for (int x = -1; x < 2; x++) {
p.setX(pos.getX() + x);
for (int z = -1; z < 2; z++) {
p.setZ(pos.getZ() + z);
if (world.isEmptyBlock(p) && world.getBlockState(p.below()).is(Blocks.WATER)) count++;
}
}
return count == 9;
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
return world.isEmptyBlock(blockPos) && world.getBlockState(blockPos.below()).is(Blocks.WATER);
}
}

View file

@ -0,0 +1,47 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.betterend.registry.EndBlocks;
public class FilaluxFeature extends SkyScatterFeature {
public FilaluxFeature() {
super(10);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
BlockState vine = EndBlocks.FILALUX.defaultBlockState();
BlockState wings = EndBlocks.FILALUX_WINGS.defaultBlockState();
BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.FILALUX_LANTERN);
BlocksHelper.setWithoutUpdate(
world,
blockPos.above(),
wings.setValue(BlockStateProperties.FACING, Direction.UP)
);
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlocksHelper.setWithoutUpdate(
world,
blockPos.relative(dir),
wings.setValue(BlockStateProperties.FACING, dir)
);
}
int length = MHelper.randRange(1, 3, random);
for (int i = 1; i <= length; i++) {
TripleShape shape = length > 1 ? TripleShape.TOP : TripleShape.BOTTOM;
if (i > 1) {
shape = i == length ? TripleShape.BOTTOM : TripleShape.MIDDLE;
}
BlocksHelper.setWithoutUpdate(world, blockPos.below(i), vine.setValue(BlockProperties.TRIPLE_SHAPE, shape));
}
}
}

View file

@ -0,0 +1,63 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.util.GlobalState;
public abstract class FullHeightScatterFeature extends DefaultFeature {
private final int radius;
public FullHeightScatterFeature(int radius) {
this.radius = radius;
}
public abstract boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius);
public abstract void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos);
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
final RandomSource random = featureConfig.random();
final BlockPos center = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, center.getX(), center.getZ());
int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY);
for (int y = maxY; y > minY; y--) {
POS.set(center.getX(), y, center.getZ());
if (world.getBlockState(POS).isAir() && !world.getBlockState(POS.below()).isAir()) {
float r = MHelper.randRange(radius * 0.5F, radius, random);
int count = MHelper.floor(r * r * MHelper.randRange(1.5F, 3F, random));
for (int i = 0; i < count; i++) {
float pr = r * (float) Math.sqrt(random.nextFloat());
float theta = random.nextFloat() * MHelper.PI2;
float x = pr * (float) Math.cos(theta);
float z = pr * (float) Math.sin(theta);
POS.set(center.getX() + x, y + 5, center.getZ() + z);
int down = BlocksHelper.downRay(world, POS, 16);
if (down > 10) continue;
POS.setY(POS.getY() - down);
if (canGenerate(world, random, center, POS, r)) {
generate(world, random, POS);
}
}
}
}
return true;
}
}

View file

@ -0,0 +1,34 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import org.betterx.betterend.blocks.basis.EndPlantWithAgeBlock;
import org.betterx.betterend.registry.EndBlocks;
public class GlowPillarFeature extends ScatterFeature {
public GlowPillarFeature() {
super(9);
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
return EndBlocks.GLOWING_PILLAR_SEED.canSurvive(AIR, world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.GLOWING_PILLAR_SEED);
seed.growAdult(world, random, blockPos);
}
@Override
protected int getChance() {
return 10;
}
}

View file

@ -0,0 +1,25 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import org.betterx.betterend.blocks.HydraluxSaplingBlock;
import org.betterx.betterend.registry.EndBlocks;
public class HydraluxFeature extends UnderwaterPlantScatter {
public HydraluxFeature(int radius) {
super(radius);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
HydraluxSaplingBlock seed = (HydraluxSaplingBlock) EndBlocks.HYDRALUX_SAPLING;
seed.grow(world, random, blockPos);
}
@Override
protected int getChance() {
return 15;
}
}

View file

@ -0,0 +1,63 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.util.GlobalState;
public abstract class InvertedScatterFeature extends DefaultFeature {
private final int radius;
public InvertedScatterFeature(int radius) {
this.radius = radius;
}
public abstract boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius);
public abstract void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos);
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
final RandomSource random = featureConfig.random();
final BlockPos center = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE, center.getX(), center.getZ());
int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY);
for (int y = maxY; y > minY; y--) {
POS.set(center.getX(), y, center.getZ());
if (world.getBlockState(POS).isAir() && !world.getBlockState(POS.above()).isAir()) {
float r = MHelper.randRange(radius * 0.5F, radius, random);
int count = MHelper.floor(r * r * MHelper.randRange(0.5F, 1.5F, random));
for (int i = 0; i < count; i++) {
float pr = r * (float) Math.sqrt(random.nextFloat());
float theta = random.nextFloat() * MHelper.PI2;
float x = pr * (float) Math.cos(theta);
float z = pr * (float) Math.sin(theta);
POS.set(center.getX() + x, center.getY() - 7, center.getZ() + z);
int up = BlocksHelper.upRay(world, POS, 16);
if (up > 14) continue;
POS.setY(POS.getY() + up);
if (canGenerate(world, random, center, POS, r)) {
generate(world, random, POS);
}
}
}
}
return true;
}
}

View file

@ -0,0 +1,34 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import org.betterx.betterend.blocks.basis.EndPlantWithAgeBlock;
import org.betterx.betterend.registry.EndBlocks;
public class LanceleafFeature extends ScatterFeature {
public LanceleafFeature() {
super(7);
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
return EndBlocks.LANCELEAF_SEED.canSurvive(AIR, world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
EndPlantWithAgeBlock seed = ((EndPlantWithAgeBlock) EndBlocks.LANCELEAF_SEED);
seed.growAdult(world, random, blockPos);
}
@Override
protected int getChance() {
return 5;
}
}

View file

@ -0,0 +1,42 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.betterend.registry.EndBlocks;
import java.util.function.Function;
public class MengerSpongeFeature extends UnderwaterPlantScatter {
private static final Function<BlockState, Boolean> REPLACE;
public MengerSpongeFeature(int radius) {
super(radius);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
BlocksHelper.setWithoutUpdate(world, blockPos, EndBlocks.MENGER_SPONGE_WET);
if (random.nextBoolean()) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
BlockPos pos = blockPos.relative(dir);
if (REPLACE.apply(world.getBlockState(pos))) {
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.MENGER_SPONGE_WET);
}
}
}
}
static {
REPLACE = (state) -> {
if (state.is(EndBlocks.END_LOTUS_STEM)) {
return false;
}
return !state.getFluidState().isEmpty() || state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,30 @@
package org.betterx.betterend.world.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 org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.NeonCactusPlantBlock;
import org.betterx.betterend.registry.EndBlocks;
public class NeonCactusFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
BlockState ground = world.getBlockState(pos.below());
if (!ground.is(EndBlocks.ENDSTONE_DUST) && !ground.is(EndBlocks.END_MOSS)) {
return false;
}
NeonCactusPlantBlock cactus = ((NeonCactusPlantBlock) EndBlocks.NEON_CACTUS);
cactus.growPlant(world, pos, random);
return true;
}
}

View file

@ -0,0 +1,92 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.util.GlobalState;
public abstract class ScatterFeature extends DefaultFeature {
private final int radius;
public ScatterFeature(int radius) {
this.radius = radius;
}
public abstract boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius);
public abstract void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos);
protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) {
return getPosOnSurfaceWG(world, pos);
}
protected boolean canSpawn(WorldGenLevel world, BlockPos pos) {
if (pos.getY() < 5) {
return false;
} else return world.getBlockState(pos.below()).is(CommonBlockTags.END_STONES);
}
protected boolean getGroundPlant(WorldGenLevel world, MutableBlockPos pos) {
int down = BlocksHelper.downRay(world, pos, 16);
if (down > Math.abs(getYOffset() * 2)) {
return false;
}
pos.setY(pos.getY() - down);
return true;
}
protected int getYOffset() {
return 5;
}
protected int getChance() {
return 1;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
final RandomSource random = featureConfig.random();
BlockPos center = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
center = getCenterGround(world, center);
if (!canSpawn(world, center)) {
return false;
}
float r = MHelper.randRange(radius * 0.5F, radius, random);
int count = MHelper.floor(r * r * MHelper.randRange(1.5F, 3F, random));
for (int i = 0; i < count; i++) {
float pr = r * (float) Math.sqrt(random.nextFloat());
float theta = random.nextFloat() * MHelper.PI2;
float x = pr * (float) Math.cos(theta);
float z = pr * (float) Math.sin(theta);
POS.set(center.getX() + x, center.getY() + getYOffset(), center.getZ() + z);
if (getGroundPlant(world, POS) && canGenerate(
world,
random,
center,
POS,
r
) && (getChance() < 2 || random.nextInt(getChance()) == 0)) {
generate(world, random, POS);
}
}
return true;
}
}

View file

@ -0,0 +1,67 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.util.GlobalState;
public class SilkMothNestFeature extends DefaultFeature {
private boolean canGenerate(WorldGenLevel world, BlockPos pos) {
BlockState state = world.getBlockState(pos.above());
if (state.is(BlockTags.LEAVES) || state.is(BlockTags.LOGS)) {
state = world.getBlockState(pos);
if ((state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) && world.isEmptyBlock(pos.below())) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
return !world.getBlockState(pos.below().relative(dir)).getMaterial().blocksMotion();
}
}
}
return false;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
final RandomSource random = featureConfig.random();
final BlockPos center = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE, center.getX(), center.getZ());
int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY);
POS.set(center);
for (int y = maxY; y > minY; y--) {
POS.setY(y);
if (canGenerate(world, POS)) {
Direction dir = BlocksHelper.randomHorizontal(random);
BlocksHelper.setWithoutUpdate(
world,
POS,
EndBlocks.SILK_MOTH_NEST.defaultBlockState()
.setValue(BlockStateProperties.HORIZONTAL_FACING, dir)
.setValue(BlockProperties.ACTIVE, false)
);
POS.setY(y - 1);
BlocksHelper.setWithoutUpdate(
world,
POS,
EndBlocks.SILK_MOTH_NEST.defaultBlockState()
.setValue(BlockStateProperties.HORIZONTAL_FACING, dir)
);
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,46 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.betterx.bclib.blocks.BaseAttachedBlock;
import org.betterx.bclib.util.BlocksHelper;
public class SingleInvertedScatterFeature extends InvertedScatterFeature {
private final Block block;
public SingleInvertedScatterFeature(Block block, int radius) {
super(radius);
this.block = block;
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
if (!world.isEmptyBlock(blockPos)) {
return false;
}
BlockState state = block.defaultBlockState();
if (block instanceof BaseAttachedBlock) {
state = state.setValue(BlockStateProperties.FACING, Direction.DOWN);
}
return state.canSurvive(world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
BlockState state = block.defaultBlockState();
if (block instanceof BaseAttachedBlock) {
state = state.setValue(BlockStateProperties.FACING, Direction.DOWN);
}
BlocksHelper.setWithoutUpdate(world, blockPos, state);
}
}

View file

@ -0,0 +1,74 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.blocks.BaseCropBlock;
import org.betterx.bclib.blocks.BaseDoublePlantBlock;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.betterend.blocks.basis.EndPlantWithAgeBlock;
public class SinglePlantFeature extends ScatterFeature {
private final Block plant;
private final boolean rawHeightmap;
private final int chance;
public SinglePlantFeature(Block plant, int radius) {
this(plant, radius, true, 1);
}
public SinglePlantFeature(Block plant, int radius, int chance) {
this(plant, radius, true, chance);
}
public SinglePlantFeature(Block plant, int radius, boolean rawHeightmap) {
this(plant, radius, rawHeightmap, 1);
}
public SinglePlantFeature(Block plant, int radius, boolean rawHeightmap, int chance) {
super(radius);
this.plant = plant;
this.rawHeightmap = rawHeightmap;
this.chance = chance;
}
protected int getChance() {
return chance;
}
@Override
protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) {
return rawHeightmap ? getPosOnSurfaceWG(world, pos) : getPosOnSurface(world, pos);
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
return plant.canSurvive(plant.defaultBlockState(), world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
if (plant instanceof BaseDoublePlantBlock) {
int rot = random.nextInt(4);
BlockState state = plant.defaultBlockState().setValue(BaseDoublePlantBlock.ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, blockPos, state);
BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(BaseDoublePlantBlock.TOP, true));
} else if (plant instanceof BaseCropBlock) {
BlockState state = plant.defaultBlockState().setValue(BaseCropBlock.AGE, 3);
BlocksHelper.setWithoutUpdate(world, blockPos, state);
} else if (plant instanceof EndPlantWithAgeBlock) {
int age = random.nextInt(4);
BlockState state = plant.defaultBlockState().setValue(EndPlantWithAgeBlock.AGE, age);
BlocksHelper.setWithoutUpdate(world, blockPos, state);
} else {
BlocksHelper.setWithoutUpdate(world, blockPos, plant);
}
}
}

View file

@ -0,0 +1,58 @@
package org.betterx.betterend.world.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 org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
public abstract class SkyScatterFeature extends ScatterFeature {
public SkyScatterFeature(int radius) {
super(radius);
}
@Override
protected int getChance() {
return 10;
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
if (!world.isEmptyBlock(blockPos)) {
return false;
}
for (Direction dir : BlocksHelper.HORIZONTAL) {
if (!world.isEmptyBlock(blockPos.relative(dir))) {
return false;
}
}
int maxD = getYOffset() + 2;
int maxV = getYOffset() - 2;
return BlocksHelper.upRay(world, blockPos, maxD) > maxV && BlocksHelper.downRay(world, blockPos, maxD) > maxV;
}
@Override
protected boolean canSpawn(WorldGenLevel world, BlockPos pos) {
return true;
}
@Override
protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) {
return new BlockPos(pos.getX(), MHelper.randRange(32, 192, world.getRandom()), pos.getZ());
}
protected boolean getGroundPlant(WorldGenLevel world, MutableBlockPos pos) {
pos.setY(pos.getY() + MHelper.randRange(-getYOffset(), getYOffset(), world.getRandom()));
return true;
}
}

View file

@ -0,0 +1,40 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.blocks.BaseDoublePlantBlock;
import org.betterx.bclib.util.BlocksHelper;
public class UnderwaterPlantFeature extends UnderwaterPlantScatter {
private final Block plant;
public UnderwaterPlantFeature(Block plant, int radius) {
super(radius);
this.plant = plant;
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
return super.canSpawn(world, blockPos) && plant.canSurvive(plant.defaultBlockState(), world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
if (plant instanceof BaseDoublePlantBlock) {
int rot = random.nextInt(4);
BlockState state = plant.defaultBlockState().setValue(BaseDoublePlantBlock.ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, blockPos, state);
BlocksHelper.setWithoutUpdate(world, blockPos.above(), state.setValue(BaseDoublePlantBlock.TOP, true));
} else {
BlocksHelper.setWithoutUpdate(world, blockPos, plant);
}
}
}

View file

@ -0,0 +1,60 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import org.betterx.betterend.util.GlobalState;
public abstract class UnderwaterPlantScatter extends ScatterFeature {
public UnderwaterPlantScatter(int radius) {
super(radius);
}
@Override
protected BlockPos getCenterGround(WorldGenLevel world, BlockPos pos) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
POS.setX(pos.getX());
POS.setZ(pos.getZ());
POS.setY(0);
return getGround(world, POS).immutable();
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
return world.getBlockState(blockPos).is(Blocks.WATER);
}
@Override
protected boolean canSpawn(WorldGenLevel world, BlockPos pos) {
return world.getBlockState(pos).is(Blocks.WATER);
}
@Override
protected boolean getGroundPlant(WorldGenLevel world, MutableBlockPos pos) {
return getGround(world, pos).getY() < 128;
}
@Override
protected int getYOffset() {
return -5;
}
@Override
protected int getChance() {
return 5;
}
private BlockPos getGround(WorldGenLevel world, MutableBlockPos pos) {
while (pos.getY() < 128 && world.getFluidState(pos).isEmpty()) {
pos.setY(pos.getY() + 1);
}
return pos;
}
}

View file

@ -0,0 +1,73 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.betterx.bclib.blocks.BaseVineBlock;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.util.BlocksHelper;
public class VineFeature extends InvertedScatterFeature {
private final Block vineBlock;
private final int maxLength;
private final boolean vine;
public VineFeature(Block vineBlock, int maxLength) {
super(6);
this.vineBlock = vineBlock;
this.maxLength = maxLength;
this.vine = vineBlock instanceof BaseVineBlock;
}
@Override
public boolean canGenerate(WorldGenLevel world,
RandomSource random,
BlockPos center,
BlockPos blockPos,
float radius) {
BlockState state = world.getBlockState(blockPos);
return state.getMaterial().isReplaceable() && canPlaceBlock(state, world, blockPos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos blockPos) {
int h = BlocksHelper.downRay(world, blockPos, random.nextInt(maxLength)) - 1;
if (h > 2) {
BlockState top = getTopState();
BlockState middle = getMiggleState();
BlockState bottom = getBottomState();
BlocksHelper.setWithoutUpdate(world, blockPos, top);
for (int i = 1; i < h; i++) {
BlocksHelper.setWithoutUpdate(world, blockPos.below(i), middle);
}
BlocksHelper.setWithoutUpdate(world, blockPos.below(h), bottom);
}
}
private boolean canPlaceBlock(BlockState state, WorldGenLevel world, BlockPos blockPos) {
if (vine) {
return ((BaseVineBlock) vineBlock).canGenerate(state, world, blockPos);
} else {
return vineBlock.canSurvive(state, world, blockPos);
}
}
private BlockState getTopState() {
BlockState state = vineBlock.defaultBlockState();
return vine ? state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP) : state;
}
private BlockState getMiggleState() {
BlockState state = vineBlock.defaultBlockState();
return vine ? state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE) : state;
}
private BlockState getBottomState() {
BlockState state = vineBlock.defaultBlockState();
return vine ? state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM) : state;
}
}

View file

@ -0,0 +1,45 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import org.betterx.bclib.blocks.BaseAttachedBlock;
import org.betterx.bclib.blocks.BaseWallPlantBlock;
import org.betterx.bclib.util.BlocksHelper;
public class WallPlantFeature extends WallScatterFeature {
private final Block block;
public WallPlantFeature(Block block, int radius) {
super(radius);
this.block = block;
}
@Override
public boolean canGenerate(WorldGenLevel world, RandomSource random, BlockPos pos, Direction dir) {
if (block instanceof BaseWallPlantBlock) {
BlockState state = block.defaultBlockState().setValue(BaseWallPlantBlock.FACING, dir);
return block.canSurvive(state, world, pos);
} else if (block instanceof BaseAttachedBlock) {
BlockState state = block.defaultBlockState().setValue(BlockStateProperties.FACING, dir);
return block.canSurvive(state, world, pos);
}
return block.canSurvive(block.defaultBlockState(), world, pos);
}
@Override
public void generate(WorldGenLevel world, RandomSource random, BlockPos pos, Direction dir) {
BlockState state = block.defaultBlockState();
if (block instanceof BaseWallPlantBlock) {
state = state.setValue(BaseWallPlantBlock.FACING, dir);
} else if (block instanceof BaseAttachedBlock) {
state = state.setValue(BlockStateProperties.FACING, dir);
}
BlocksHelper.setWithoutUpdate(world, pos, state);
}
}

View file

@ -0,0 +1,22 @@
package org.betterx.betterend.world.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
public class WallPlantOnLogFeature extends WallPlantFeature {
public WallPlantOnLogFeature(Block block, int radius) {
super(block, radius);
}
@Override
public boolean canGenerate(WorldGenLevel world, RandomSource random, BlockPos pos, Direction dir) {
BlockPos blockPos = pos.relative(dir.getOpposite());
BlockState blockState = world.getBlockState(blockPos);
return blockState.is(BlockTags.LOGS);
}
}

View file

@ -0,0 +1,71 @@
package org.betterx.betterend.world.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.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
public abstract class WallScatterFeature extends DefaultFeature {
private static final Direction[] DIR = BlocksHelper.makeHorizontal();
private final int radius;
public WallScatterFeature(int radius) {
this.radius = radius;
}
public abstract boolean canGenerate(WorldGenLevel world, RandomSource random, BlockPos pos, Direction dir);
public abstract void generate(WorldGenLevel world, RandomSource random, BlockPos pos, Direction dir);
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos center = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
int maxY = world.getHeight(Heightmap.Types.WORLD_SURFACE, center.getX(), center.getZ());
int minY = BlocksHelper.upRay(world, new BlockPos(center.getX(), 0, center.getZ()), maxY);
if (maxY < 10 || maxY < minY) {
return false;
}
int py = MHelper.randRange(minY, maxY, random);
MutableBlockPos mut = new MutableBlockPos();
for (int x = -radius; x <= radius; x++) {
mut.setX(center.getX() + x);
for (int y = -radius; y <= radius; y++) {
mut.setY(py + y);
for (int z = -radius; z <= radius; z++) {
mut.setZ(center.getZ() + z);
if (random.nextInt(4) == 0 && world.isEmptyBlock(mut)) {
shuffle(random);
for (Direction dir : DIR) {
if (canGenerate(world, random, mut, dir)) {
generate(world, random, mut, dir);
break;
}
}
}
}
}
}
return true;
}
private void shuffle(RandomSource random) {
for (int i = 0; i < 4; i++) {
int j = random.nextInt(4);
Direction d = DIR[i];
DIR[i] = DIR[j];
DIR[j] = d;
}
}
}

View file

@ -0,0 +1,99 @@
package org.betterx.betterend.world.features.bushes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
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 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.SDFScale3D;
import org.betterx.bclib.sdf.operator.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import java.util.function.Function;
public class BushFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private final Block leaves;
private final Block stem;
public BushFeature(Block leaves, Block stem) {
this.leaves = leaves;
this.stem = stem;
}
@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) && !world.getBlockState(pos.above())
.is(CommonBlockTags.END_STONES))
return false;
float radius = MHelper.randRange(1.8F, 3.5F, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
SDF sphere = new SDFSphere().setRadius(radius).setBlock(this.leaves);
sphere = new SDFScale3D().setScale(1, 0.5F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 3;
}).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return MHelper.randRange(-2F, 2F, random);
}).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere)
.setSourceB(new SDFTranslate().setTranslate(0, -radius, 0).setSource(sphere));
sphere.setReplaceFunction(REPLACE);
sphere.addPostProcess((info) -> {
if (info.getState().getBlock() instanceof LeavesBlock) {
int distance = info.getPos().distManhattan(pos);
if (distance < 7) {
return info.getState().setValue(LeavesBlock.DISTANCE, distance);
} else {
return AIR;
}
}
return info.getState();
});
sphere.fillRecursive(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, stem);
for (Direction d : Direction.values()) {
BlockPos p = pos.relative(d);
if (world.isEmptyBlock(p)) {
if (leaves instanceof LeavesBlock) {
BlocksHelper.setWithoutUpdate(
world,
p,
leaves.defaultBlockState().setValue(LeavesBlock.DISTANCE, 1)
);
} else {
BlocksHelper.setWithoutUpdate(world, p, leaves.defaultBlockState());
}
}
}
return true;
}
static {
REPLACE = (state) -> {
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,116 @@
package org.betterx.betterend.world.features.bushes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
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 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.SDFScale3D;
import org.betterx.bclib.sdf.operator.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import java.util.function.Function;
public class BushWithOuterFeature extends DefaultFeature {
private static final Direction[] DIRECTIONS = Direction.values();
private static final Function<BlockState, Boolean> REPLACE;
private final Block outer_leaves;
private final Block leaves;
private final Block stem;
public BushWithOuterFeature(Block leaves, Block outer_leaves, Block stem) {
this.outer_leaves = outer_leaves;
this.leaves = leaves;
this.stem = stem;
}
@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) && !world.getBlockState(pos.above())
.is(CommonBlockTags.END_STONES))
return false;
float radius = MHelper.randRange(1.8F, 3.5F, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
SDF sphere = new SDFSphere().setRadius(radius).setBlock(this.leaves);
sphere = new SDFScale3D().setScale(1, 0.5F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 3;
}).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return MHelper.randRange(-2F, 2F, random);
}).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere)
.setSourceB(new SDFTranslate().setTranslate(0, -radius, 0).setSource(sphere));
sphere.setReplaceFunction(REPLACE);
sphere.addPostProcess((info) -> {
if (info.getState().getBlock() instanceof LeavesBlock) {
int distance = info.getPos().distManhattan(pos);
if (distance < 7) {
return info.getState().setValue(LeavesBlock.DISTANCE, distance);
} else {
return AIR;
}
}
return info.getState();
}).addPostProcess((info) -> {
if (info.getState().getBlock() instanceof LeavesBlock) {
MHelper.shuffle(DIRECTIONS, random);
for (Direction dir : DIRECTIONS) {
if (info.getState(dir).isAir()) {
info.setBlockPos(
info.getPos().relative(dir),
outer_leaves.defaultBlockState().setValue(BlockStateProperties.FACING, dir)
);
}
}
}
return info.getState();
});
sphere.fillRecursive(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, stem);
for (Direction d : Direction.values()) {
BlockPos p = pos.relative(d);
if (world.isEmptyBlock(p)) {
if (leaves instanceof LeavesBlock) {
BlocksHelper.setWithoutUpdate(
world,
p,
leaves.defaultBlockState().setValue(LeavesBlock.DISTANCE, 1)
);
} else {
BlocksHelper.setWithoutUpdate(world, p, leaves.defaultBlockState());
}
}
}
return true;
}
static {
REPLACE = (state) -> {
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,55 @@
package org.betterx.betterend.world.features.bushes;
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.state.BlockState;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.registry.EndBlocks;
public class LargeAmaranitaFeature 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;
MutableBlockPos mut = new MutableBlockPos().set(pos);
int height = MHelper.randRange(2, 3, random);
for (int i = 1; i < height; i++) {
mut.setY(mut.getY() + 1);
if (!world.isEmptyBlock(mut)) {
return false;
}
}
mut.set(pos);
BlockState state = EndBlocks.LARGE_AMARANITA_MUSHROOM.defaultBlockState();
BlocksHelper.setWithUpdate(world, mut, state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM));
if (height > 2) {
BlocksHelper.setWithUpdate(
world,
mut.move(Direction.UP),
state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE)
);
}
BlocksHelper.setWithUpdate(
world,
mut.move(Direction.UP),
state.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP)
);
return true;
}
}

View file

@ -0,0 +1,82 @@
package org.betterx.betterend.world.features.bushes;
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.state.BlockState;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.EndBlockProperties.LumecornShape;
import org.betterx.betterend.blocks.LumecornBlock;
import org.betterx.betterend.registry.EndBlocks;
public class Lumecorn 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;
int height = MHelper.randRange(4, 7, random);
MutableBlockPos mut = new MutableBlockPos().set(pos);
for (int i = 1; i < height; i++) {
mut.move(Direction.UP);
if (!world.isEmptyBlock(mut)) {
return false;
}
}
mut.set(pos);
BlockState topMiddle = EndBlocks.LUMECORN.defaultBlockState()
.setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_TOP_MIDDLE);
BlockState middle = EndBlocks.LUMECORN.defaultBlockState()
.setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_MIDDLE);
BlockState bottom = EndBlocks.LUMECORN.defaultBlockState()
.setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_BOTTOM);
BlockState top = EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.LIGHT_TOP);
if (height == 4) {
BlocksHelper.setWithoutUpdate(
world,
mut,
EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.BOTTOM_SMALL)
);
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), bottom);
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), topMiddle);
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), top);
return true;
}
if (random.nextBoolean()) {
BlocksHelper.setWithoutUpdate(
world,
mut,
EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.BOTTOM_SMALL)
);
} else {
BlocksHelper.setWithoutUpdate(
world,
mut,
EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.BOTTOM_BIG)
);
BlocksHelper.setWithoutUpdate(
world,
mut.move(Direction.UP),
EndBlocks.LUMECORN.defaultBlockState().setValue(LumecornBlock.SHAPE, LumecornShape.MIDDLE)
);
height--;
}
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), bottom);
for (int i = 4; i < height; i++) {
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), middle);
}
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), topMiddle);
BlocksHelper.setWithoutUpdate(world, mut.move(Direction.UP), top);
return false;
}
}

View file

@ -0,0 +1,137 @@
package org.betterx.betterend.world.features.bushes;
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.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.collect.Lists;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFDisplacement;
import org.betterx.bclib.sdf.operator.SDFScale3D;
import org.betterx.bclib.sdf.operator.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.basis.FurBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class TenaneaBushFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final Direction[] DIRECTIONS = Direction.values();
public TenaneaBushFeature() {
}
@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;
float radius = MHelper.randRange(1.8F, 3.5F, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
BlockState leaves = EndBlocks.TENANEA_LEAVES.defaultBlockState();
SDF sphere = new SDFSphere().setRadius(radius).setBlock(leaves);
sphere = new SDFScale3D().setScale(1, 0.75F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> (float) noise.eval(
vec.x() * 0.2,
vec.y() * 0.2,
vec.z() * 0.2
) * 3).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> MHelper.randRange(-2F, 2F, random)).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere)
.setSourceB(new SDFTranslate().setTranslate(0, -radius, 0).setSource(sphere));
sphere.setReplaceFunction(REPLACE);
List<BlockPos> support = Lists.newArrayList();
sphere.addPostProcess((info) -> {
if (info.getState().getBlock() instanceof LeavesBlock) {
int distance = info.getPos().distManhattan(pos);
if (distance < 7) {
if (random.nextInt(4) == 0 && info.getStateDown().isAir()) {
BlockPos d = info.getPos().below();
support.add(d);
}
MHelper.shuffle(DIRECTIONS, random);
for (Direction d : DIRECTIONS) {
if (info.getState(d).isAir()) {
info.setBlockPos(
info.getPos().relative(d),
EndBlocks.TENANEA_OUTER_LEAVES.defaultBlockState().setValue(FurBlock.FACING, d)
);
}
}
return info.getState().setValue(LeavesBlock.DISTANCE, distance);
} else {
return AIR;
}
}
return info.getState();
});
sphere.fillRecursive(world, pos);
BlockState stem = EndBlocks.TENANEA.getBark().defaultBlockState();
BlocksHelper.setWithoutUpdate(world, pos, stem);
for (Direction d : Direction.values()) {
BlockPos p = pos.relative(d);
if (world.isEmptyBlock(p)) {
BlocksHelper.setWithoutUpdate(world, p, leaves.setValue(LeavesBlock.DISTANCE, 1));
}
}
MutableBlockPos mut = new MutableBlockPos();
BlockState top = EndBlocks.TENANEA_FLOWERS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP);
BlockState middle = EndBlocks.TENANEA_FLOWERS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
BlockState bottom = EndBlocks.TENANEA_FLOWERS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
support.forEach((bpos) -> {
BlockState state = world.getBlockState(bpos);
if (state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) {
int count = MHelper.randRange(3, 8, random);
mut.set(bpos);
if (world.getBlockState(mut.above()).is(EndBlocks.TENANEA_LEAVES)) {
BlocksHelper.setWithoutUpdate(world, mut, top);
for (int i = 1; i < count; i++) {
mut.setY(mut.getY() - 1);
if (world.isEmptyBlock(mut.below())) {
BlocksHelper.setWithoutUpdate(world, mut, middle);
} else {
break;
}
}
BlocksHelper.setWithoutUpdate(world, mut, bottom);
}
}
});
return true;
}
static {
REPLACE = (state) -> {
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,86 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
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.phys.AABB;
import net.minecraft.world.phys.Vec3;
import com.google.common.collect.Lists;
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.SDFRotation;
import org.betterx.bclib.sdf.primitive.SDFTorus;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import java.util.List;
import java.util.function.Function;
public class ArchFeature extends DefaultFeature {
private final Function<BlockPos, BlockState> surfaceFunction;
private final Block block;
public ArchFeature(Block block, Function<BlockPos, BlockState> surfaceFunction) {
this.surfaceFunction = surfaceFunction;
this.block = block;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
final WorldGenLevel world = featurePlaceContext.level();
BlockPos origin = featurePlaceContext.origin();
RandomSource random = featurePlaceContext.random();
BlockPos pos = getPosOnSurfaceWG(
world,
new BlockPos((origin.getX() & 0xFFFFFFF0) | 7, 0, (origin.getZ() & 0xFFFFFFF0) | 7)
);
if (!world.getBlockState(pos.below(5)).is(CommonBlockTags.GEN_END_STONES)) {
return false;
}
float bigRadius = MHelper.randRange(10F, 20F, random);
float smallRadius = MHelper.randRange(3F, 7F, random);
if (smallRadius + bigRadius > 23) {
smallRadius = 23 - bigRadius;
}
SDF arch = new SDFTorus().setBigRadius(bigRadius).setSmallRadius(smallRadius).setBlock(block);
arch = new SDFRotation().setRotation(MHelper.randomHorizontal(random), (float) Math.PI * 0.5F).setSource(arch);
final float smallRadiusF = smallRadius;
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
arch = new SDFDisplacement().setFunction((vec) -> {
return (float) (Math.abs(noise.eval(vec.x() * 0.1,
vec.y() * 0.1,
vec.z() * 0.1
)) * 3F + Math.abs(noise.eval(
vec.x() * 0.3,
vec.y() * 0.3 + 100,
vec.z() * 0.3
)) * 1.3F) - smallRadiusF * Math.abs(1 - vec.y() / bigRadius);
}).setSource(arch);
List<BlockPos> surface = Lists.newArrayList();
arch.addPostProcess((info) -> {
if (info.getStateUp().isAir()) {
return surfaceFunction.apply(info.getPos());
}
return info.getState();
});
float side = (bigRadius + smallRadius + 3F) * 2;
if (side > 47) {
side = 47;
}
arch.fillArea(world, pos, AABB.ofSize(Vec3.atCenterOf(pos), side, side, side));
return true;
}
}

View file

@ -0,0 +1,54 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
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.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFRotation;
import org.betterx.bclib.sdf.primitive.SDFHexPrism;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.registry.EndBlocks;
public class BigAuroraCrystalFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
int maxY = pos.getY() + BlocksHelper.upRay(world, pos, 16);
int minY = pos.getY() - BlocksHelper.downRay(world, pos, 16);
if (maxY - minY < 10) {
return false;
}
int y = MHelper.randRange(minY, maxY, random);
pos = new BlockPos(pos.getX(), y, pos.getZ());
int height = MHelper.randRange(5, 25, random);
SDF prism = new SDFHexPrism().setHeight(height)
.setRadius(MHelper.randRange(1.7F, 3F, random))
.setBlock(EndBlocks.AURORA_CRYSTAL);
Vector3f vec = MHelper.randomHorizontal(random);
prism = new SDFRotation().setRotation(vec, random.nextFloat()).setSource(prism);
prism.setReplaceFunction((bState) -> {
return bState.getMaterial()
.isReplaceable() || bState.is(CommonBlockTags.GEN_END_STONES) || bState.getMaterial()
.equals(Material.PLANT) || bState
.getMaterial()
.equals(Material.LEAVES);
});
prism.fillRecursive(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.AURORA_CRYSTAL);
return true;
}
}

View file

@ -0,0 +1,242 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
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.FluidState;
import net.minecraft.world.level.material.Material;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.util.BlockFixer;
import org.betterx.betterend.util.GlobalState;
import org.betterx.betterend.world.biome.EndBiome;
public class DesertLakeFeature extends DefaultFeature {
private static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(15152);
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
final RandomSource random = featureConfig.random();
BlockPos blockPos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
double radius = MHelper.randRange(8.0, 15.0, random);
double depth = radius * 0.5 * MHelper.randRange(0.8, 1.2, random);
int dist = MHelper.floor(radius);
int dist2 = MHelper.floor(radius * 1.5);
int bott = MHelper.floor(depth);
blockPos = getPosOnSurfaceWG(world, blockPos);
if (blockPos.getY() < 10) return false;
int waterLevel = blockPos.getY();
BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
BlockState state;
int minX = blockPos.getX() - dist2;
int maxX = blockPos.getX() + dist2;
int minZ = blockPos.getZ() - dist2;
int maxZ = blockPos.getZ() + dist2;
int maskMinX = minX - 1;
int maskMinZ = minZ - 1;
boolean[][] mask = new boolean[maxX - minX + 3][maxZ - minZ + 3];
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = waterLevel + 1; y <= waterLevel + 20; y++) {
POS.setY(y);
FluidState fluid = world.getFluidState(POS);
if (!fluid.isEmpty()) {
for (int i = -1; i < 2; i++) {
int px = mx + i;
for (int j = -1; j < 2; j++) {
int pz = mz + j;
mask[px][pz] = true;
}
}
break;
}
}
}
}
}
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int x2 = x - blockPos.getX();
x2 *= x2;
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int z2 = z - blockPos.getZ();
z2 *= z2;
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
double size = 1;
for (int y = blockPos.getY(); y <= blockPos.getY() + 20; y++) {
POS.setY(y);
double add = y - blockPos.getY();
if (add > 5) {
size *= 0.8;
add = 5;
}
double r = (add * 1.8 + radius * (NOISE.eval(
x * 0.2,
y * 0.2,
z * 0.2
) * 0.25 + 0.75)) - 1.0 / size;
if (r > 0) {
r *= r;
if (x2 + z2 <= r) {
state = world.getBlockState(POS);
if (state.is(CommonBlockTags.GEN_END_STONES)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
pos = POS.below();
if (world.getBlockState(pos).is(CommonBlockTags.GEN_END_STONES)) {
state = EndBiome.findTopMaterial(world,
pos); //world.getBiome(pos).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
if (y > waterLevel + 1) BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel)
BlocksHelper.setWithoutUpdate(
world,
pos,
random.nextBoolean()
? state
: EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
else
BlocksHelper.setWithoutUpdate(
world,
pos,
EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
}
}
} else {
break;
}
}
}
}
}
double aspect = (radius / depth);
for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) {
POS.setX(x);
int x2 = x - blockPos.getX();
x2 *= x2;
int mx = x - maskMinX;
for (int z = blockPos.getZ() - dist; z <= blockPos.getZ() + dist; z++) {
POS.setZ(z);
int z2 = z - blockPos.getZ();
z2 *= z2;
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = blockPos.getY() - bott; y < blockPos.getY(); y++) {
POS.setY(y);
double y2 = (double) (y - blockPos.getY()) * aspect;
y2 *= y2;
double r = radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
double rb = r * 1.2;
r *= r;
rb *= rb;
if (y2 + x2 + z2 <= r) {
state = world.getBlockState(POS);
if (canReplace(state)) {
state = world.getBlockState(POS.above());
state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state;
BlocksHelper.setWithoutUpdate(world, POS, state);
}
pos = POS.below();
if (world.getBlockState(pos).is(CommonBlockTags.GEN_END_STONES)) {
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.defaultBlockState());
}
pos = POS.above();
while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState()
.isEmpty()) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.above();
}
}
// Make border
else if (y2 + x2 + z2 <= rb) {
state = world.getBlockState(POS);
if (state.is(CommonBlockTags.GEN_END_STONES) && world.isEmptyBlock(POS.above())) {
BlocksHelper.setWithoutUpdate(world, POS, EndBlocks.END_MOSS);
} else if (y < waterLevel) {
if (world.isEmptyBlock(POS.above())) {
state = EndBiome.findTopMaterial(world,
pos); //world.getBiome(POS).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
BlocksHelper.setWithoutUpdate(
world,
POS,
random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
BlocksHelper.setWithoutUpdate(world, POS.below(), END_STONE);
} else {
BlocksHelper.setWithoutUpdate(
world,
POS,
EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
BlocksHelper.setWithoutUpdate(world, POS.below(), END_STONE);
}
}
}
}
}
}
}
BlockFixer.fixBlocks(
world,
new BlockPos(minX - 2, waterLevel - 2, minZ - 2),
new BlockPos(maxX + 2, blockPos.getY() + 20, maxZ + 2)
);
return true;
}
private boolean canReplace(BlockState state) {
return state.getMaterial()
.isReplaceable() || state.is(CommonBlockTags.GEN_END_STONES) || state.is(EndBlocks.ENDSTONE_DUST) || state.getMaterial()
.equals(
Material.PLANT) || state
.getMaterial()
.equals(Material.WATER_PLANT);
}
}

View file

@ -0,0 +1,238 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
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.FluidState;
import net.minecraft.world.level.material.Material;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.util.BlockFixer;
import org.betterx.betterend.util.GlobalState;
import org.betterx.betterend.world.biome.EndBiome;
public class EndLakeFeature extends DefaultFeature {
private static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(15152);
public EndLakeFeature() {
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final MutableBlockPos POS = GlobalState.stateForThread().POS;
final RandomSource random = featureConfig.random();
BlockPos blockPos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
double radius = MHelper.randRange(10.0, 20.0, random);
double depth = radius * 0.5 * MHelper.randRange(0.8, 1.2, random);
int dist = MHelper.floor(radius);
int dist2 = MHelper.floor(radius * 1.5);
int bott = MHelper.floor(depth);
blockPos = getPosOnSurfaceWG(world, blockPos);
if (blockPos.getY() < 10) return false;
int waterLevel = blockPos.getY();
BlockPos pos = getPosOnSurfaceRaycast(world, blockPos.north(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.south(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.east(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
pos = getPosOnSurfaceRaycast(world, blockPos.west(dist).above(10), 20);
if (Math.abs(blockPos.getY() - pos.getY()) > 5) return false;
waterLevel = MHelper.min(pos.getY(), waterLevel);
BlockState state;
int minX = blockPos.getX() - dist2;
int maxX = blockPos.getX() + dist2;
int minZ = blockPos.getZ() - dist2;
int maxZ = blockPos.getZ() + dist2;
int maskMinX = minX - 1;
int maskMinZ = minZ - 1;
boolean[][] mask = new boolean[maxX - minX + 3][maxZ - minZ + 3];
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = waterLevel + 1; y <= waterLevel + 20; y++) {
POS.setY(y);
FluidState fluid = world.getFluidState(POS);
if (!fluid.isEmpty()) {
for (int i = -1; i < 2; i++) {
int px = mx + i;
for (int j = -1; j < 2; j++) {
int pz = mz + j;
mask[px][pz] = true;
}
}
break;
}
}
}
}
}
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int x2 = x - blockPos.getX();
x2 *= x2;
int mx = x - maskMinX;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int z2 = z - blockPos.getZ();
z2 *= z2;
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
double size = 1;
for (int y = blockPos.getY(); y <= blockPos.getY() + 20; y++) {
POS.setY(y);
double add = y - blockPos.getY();
if (add > 5) {
size *= 0.8;
add = 5;
}
double r = (add * 1.8 + radius * (NOISE.eval(
x * 0.2,
y * 0.2,
z * 0.2
) * 0.25 + 0.75)) - 1.0 / size;
if (r > 0) {
r *= r;
if (x2 + z2 <= r) {
state = world.getBlockState(POS);
if (state.is(CommonBlockTags.GEN_END_STONES)) {
BlocksHelper.setWithoutUpdate(world, POS, AIR);
}
pos = POS.below();
if (world.getBlockState(pos).is(CommonBlockTags.GEN_END_STONES)) {
state = EndBiome.findTopMaterial(world, pos);
if (y > waterLevel + 1) BlocksHelper.setWithoutUpdate(world, pos, state);
else if (y > waterLevel)
BlocksHelper.setWithoutUpdate(
world,
pos,
random.nextBoolean()
? state
: EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
else
BlocksHelper.setWithoutUpdate(
world,
pos,
EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
}
}
} else {
break;
}
}
}
}
}
double aspect = (radius / depth);
for (int x = blockPos.getX() - dist; x <= blockPos.getX() + dist; x++) {
POS.setX(x);
int x2 = x - blockPos.getX();
x2 *= x2;
int mx = x - maskMinX;
for (int z = blockPos.getZ() - dist; z <= blockPos.getZ() + dist; z++) {
POS.setZ(z);
int z2 = z - blockPos.getZ();
z2 *= z2;
int mz = z - maskMinZ;
if (!mask[mx][mz]) {
for (int y = blockPos.getY() - bott; y < blockPos.getY(); y++) {
POS.setY(y);
double y2 = (double) (y - blockPos.getY()) * aspect;
y2 *= y2;
double r = radius * (NOISE.eval(x * 0.2, y * 0.2, z * 0.2) * 0.25 + 0.75);
double rb = r * 1.2;
r *= r;
rb *= rb;
if (y2 + x2 + z2 <= r) {
state = world.getBlockState(POS);
if (canReplace(state)) {
state = world.getBlockState(POS.above());
state = canReplace(state) ? (y < waterLevel ? WATER : AIR) : state;
BlocksHelper.setWithoutUpdate(world, POS, state);
}
pos = POS.below();
if (world.getBlockState(pos).is(CommonBlockTags.GEN_END_STONES)) {
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.ENDSTONE_DUST.defaultBlockState());
}
pos = POS.above();
while (canReplace(state = world.getBlockState(pos)) && !state.isAir() && state.getFluidState()
.isEmpty()) {
BlocksHelper.setWithoutUpdate(world, pos, pos.getY() < waterLevel ? WATER : AIR);
pos = pos.above();
}
}
// Make border
else if (y < waterLevel && y2 + x2 + z2 <= rb) {
if (world.isEmptyBlock(POS.above())) {
state = EndBiome.findTopMaterial(world, pos);
// state = world.getBiome(POS)
// .getGenerationSettings()
// .getSurfaceBuilderConfig()
// .getTopMaterial();
BlocksHelper.setWithoutUpdate(
world,
POS,
random.nextBoolean() ? state : EndBlocks.ENDSTONE_DUST.defaultBlockState()
);
BlocksHelper.setWithoutUpdate(world, POS.below(), END_STONE);
} else {
BlocksHelper.setWithoutUpdate(world, POS, EndBlocks.ENDSTONE_DUST.defaultBlockState());
BlocksHelper.setWithoutUpdate(world, POS.below(), END_STONE);
}
}
}
}
}
}
BlockFixer.fixBlocks(
world,
new BlockPos(minX - 2, waterLevel - 2, minZ - 2),
new BlockPos(maxX + 2, blockPos.getY() + 20, maxZ + 2)
);
return true;
}
private boolean canReplace(BlockState state) {
return state.getMaterial()
.isReplaceable() || state.is(CommonBlockTags.GEN_END_STONES) || state.is(EndBlocks.ENDSTONE_DUST) || state.getMaterial()
.equals(
Material.PLANT) || state
.getMaterial()
.equals(Material.WATER_PLANT);
}
}

View file

@ -0,0 +1,67 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
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 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.SDFRotation;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
public class FallenPillarFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
pos = getPosOnSurface(
world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))
);
if (!world.getBlockState(pos.below(5)).is(CommonBlockTags.GEN_END_STONES)) {
return false;
}
float height = MHelper.randRange(20F, 40F, random);
float radius = MHelper.randRange(2F, 4F, random);
SDF pillar = new SDFCappedCone().setRadius1(radius)
.setRadius2(radius)
.setHeight(height * 0.5F)
.setBlock(Blocks.OBSIDIAN);
pillar = new SDFTranslate().setTranslate(0, radius * 0.5F - 2, 0).setSource(pillar);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
pillar = new SDFDisplacement().setFunction((vec) -> {
return (float) (noise.eval(vec.x() * 0.3, vec.y() * 0.3, vec.z() * 0.3) * 0.5F);
}).setSource(pillar);
Vector3f vec = MHelper.randomHorizontal(random);
float angle = (float) random.nextGaussian() * 0.05F + (float) Math.PI;
pillar = new SDFRotation().setRotation(vec, angle).setSource(pillar);
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.defaultBlockState();
pillar.addPostProcess((info) -> {
if (info.getStateUp().isAir() && random.nextFloat() > 0.1F) {
return mossy;
}
return info.getState();
}).setReplaceFunction((state) -> {
return state.getMaterial()
.isReplaceable() || state.is(CommonBlockTags.GEN_END_STONES) || state.getMaterial()
.equals(Material.PLANT);
}).fillRecursive(world, pos);
return true;
}
}

View file

@ -0,0 +1,97 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
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.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import com.google.common.collect.Lists;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFDisplacement;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.MHelper;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.world.biome.EndBiome;
import java.util.List;
import java.util.Optional;
public class FloatingSpireFeature extends SpireFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
final ChunkGenerator chunkGenerator = featureConfig.chunkGenerator();
int minY = getYOnSurface(world, pos.getX(), pos.getZ());
int y = minY > 57 ? MHelper.floor(MHelper.randRange(minY, minY * 2, random) * 0.5F + 32) : MHelper.randRange(
64,
192,
random
);
pos = new BlockPos(pos.getX(), y, pos.getZ());
SDF sdf = new SDFSphere().setRadius(MHelper.randRange(2, 3, random)).setBlock(Blocks.END_STONE);
int count = MHelper.randRange(3, 5, random);
for (int i = 0; i < count; i++) {
float rMin = (i * 1.3F) + 2.5F;
sdf = addSegment(sdf, MHelper.randRange(rMin, rMin + 1.5F, random), random);
}
for (int i = count - 1; i > 0; i--) {
float rMin = (i * 1.3F) + 2.5F;
sdf = addSegment(sdf, MHelper.randRange(rMin, rMin + 1.5F, random), random);
}
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
sdf = new SDFDisplacement().setFunction((vec) -> {
return (float) (Math.abs(noise.eval(
vec.x() * 0.1,
vec.y() * 0.1,
vec.z() * 0.1
)) * 3F + Math.abs(noise.eval(vec.x() * 0.3,
vec.y() * 0.3 + 100,
vec.z() * 0.3)) * 1.3F);
}).setSource(sdf);
final BlockPos center = pos;
List<BlockPos> support = Lists.newArrayList();
sdf.setReplaceFunction(REPLACE).addPostProcess((info) -> {
if (info.getStateUp().isAir()) {
if (random.nextInt(16) == 0) {
support.add(info.getPos().above());
}
return EndBiome.findTopMaterial(world,
info.getPos());//world.getBiome(info.getPos()).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
} else if (info.getState(Direction.UP, 3).isAir()) {
return EndBiome.findUnderMaterial(world, info.getPos());
// return world.getBiome(info.getPos())
// .getGenerationSettings()
// .getSurfaceBuilderConfig()
// .getUnderMaterial();
}
return info.getState();
});
sdf.fillRecursive(world, center);
support.forEach((bpos) -> {
if (BiomeAPI.getFromBiome(world.getBiome(bpos)) == EndBiomes.BLOSSOMING_SPIRES) {
EndFeatures.TENANEA_BUSH.getFeature()
.place(new FeaturePlaceContext<>(Optional.empty(),
world,
chunkGenerator,
random,
bpos,
null));
}
});
return true;
}
}

View file

@ -0,0 +1,292 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
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.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
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.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.*;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.sdf.primitive.SDFFlatland;
import org.betterx.bclib.sdf.primitive.SDFPrimitive;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.HydrothermalVentBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.util.BlockFixer;
import java.util.Optional;
import java.util.function.Function;
public class GeyserFeature extends DefaultFeature {
protected static final Function<BlockState, Boolean> REPLACE1;
protected static final Function<BlockState, Boolean> REPLACE2;
private static final Function<BlockState, Boolean> IGNORE;
private static final Direction[] HORIZONTAL = BlocksHelper.makeHorizontal();
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final WorldGenLevel world = featureConfig.level();
final BlockPos pos = getPosOnSurfaceWG(world, featureConfig.origin());
final ChunkGenerator chunkGenerator = featureConfig.chunkGenerator();
if (pos.getY() < 10) {
return false;
}
MutableBlockPos bpos = new MutableBlockPos().set(pos);
bpos.setY(bpos.getY() - 1);
BlockState state = world.getBlockState(bpos);
while (state.is(CommonBlockTags.GEN_END_STONES) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
if (pos.getY() - bpos.getY() < 25) {
return false;
}
int halfHeight = MHelper.randRange(10, 20, random);
float radius1 = halfHeight * 0.5F;
float radius2 = halfHeight * 0.1F + 0.5F;
SDF sdf = new SDFCappedCone().setHeight(halfHeight)
.setRadius1(radius1)
.setRadius2(radius2)
.setBlock(EndBlocks.SULPHURIC_ROCK.stone);
sdf = new SDFTranslate().setTranslate(0, halfHeight - 3, 0).setSource(sdf);
int count = halfHeight;
for (int i = 0; i < count; i++) {
int py = i << 1;
float delta = (float) i / (float) (count - 1);
float radius = Mth.lerp(delta, radius1, radius2) * 1.3F;
SDF bowl = new SDFCappedCone().setHeight(radius)
.setRadius1(0)
.setRadius2(radius)
.setBlock(EndBlocks.SULPHURIC_ROCK.stone);
SDF brimstone = new SDFCappedCone().setHeight(radius)
.setRadius1(0)
.setRadius2(radius)
.setBlock(EndBlocks.BRIMSTONE);
brimstone = new SDFTranslate().setTranslate(0, 2F, 0).setSource(brimstone);
bowl = new SDFSubtraction().setSourceA(bowl).setSourceB(brimstone);
bowl = new SDFUnion().setSourceA(brimstone).setSourceB(bowl);
SDF water = new SDFCappedCone().setHeight(radius).setRadius1(0).setRadius2(radius).setBlock(Blocks.WATER);
water = new SDFTranslate().setTranslate(0, 4, 0).setSource(water);
bowl = new SDFSubtraction().setSourceA(bowl).setSourceB(water);
bowl = new SDFUnion().setSourceA(water).setSourceB(bowl);
final OpenSimplexNoise noise1 = new OpenSimplexNoise(random.nextLong());
final OpenSimplexNoise noise2 = new OpenSimplexNoise(random.nextLong());
bowl = new SDFCoordModify().setFunction((vec) -> {
float dx = (float) noise1.eval(vec.x() * 0.1, vec.y() * 0.1, vec.z() * 0.1);
float dz = (float) noise2.eval(vec.x() * 0.1, vec.y() * 0.1, vec.z() * 0.1);
vec.set(vec.x() + dx, vec.y(), vec.z() + dz);
}).setSource(bowl);
SDF cut = new SDFFlatland().setBlock(Blocks.AIR);
cut = new SDFInvert().setSource(cut);
cut = new SDFTranslate().setTranslate(0, radius - 2, 0).setSource(cut);
bowl = new SDFSubtraction().setSourceA(bowl).setSourceB(cut);
bowl = new SDFTranslate().setTranslate(radius, py - radius, 0).setSource(bowl);
bowl = new SDFRotation().setRotation(Vector3f.YP, i * 4F).setSource(bowl);
sdf = new SDFUnion().setSourceA(sdf).setSourceB(bowl);
}
sdf.setReplaceFunction(REPLACE2).fillRecursive(world, pos);
radius2 = radius2 * 0.5F;
if (radius2 < 0.7F) {
radius2 = 0.7F;
}
final OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
SDFPrimitive obj1;
SDFPrimitive obj2;
obj1 = new SDFCappedCone().setHeight(halfHeight + 5).setRadius1(radius1 * 0.5F).setRadius2(radius2);
sdf = new SDFTranslate().setTranslate(0, halfHeight - 13, 0).setSource(obj1);
sdf = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.3F, vec.y() * 0.3F, vec.z() * 0.3F) * 0.5F;
}).setSource(sdf);
obj2 = new SDFSphere().setRadius(radius1);
SDF cave = new SDFScale3D().setScale(1.5F, 1, 1.5F).setSource(obj2);
cave = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.1F, vec.y() * 0.1F, vec.z() * 0.1F) * 2F;
}).setSource(cave);
cave = new SDFTranslate().setTranslate(0, -halfHeight - 10, 0).setSource(cave);
sdf = new SDFSmoothUnion().setRadius(5).setSourceA(cave).setSourceB(sdf);
obj1.setBlock(WATER);
obj2.setBlock(WATER);
sdf.setReplaceFunction(REPLACE2);
sdf.fillRecursive(world, pos);
obj1.setBlock(EndBlocks.BRIMSTONE);
obj2.setBlock(EndBlocks.BRIMSTONE);
new SDFDisplacement().setFunction((vec) -> {
return -2F;
}).setSource(sdf).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE);
obj1.setBlock(EndBlocks.SULPHURIC_ROCK.stone);
obj2.setBlock(EndBlocks.SULPHURIC_ROCK.stone);
new SDFDisplacement().setFunction((vec) -> {
return -4F;
}).setSource(cave).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE);
obj1.setBlock(Blocks.END_STONE);
obj2.setBlock(Blocks.END_STONE);
new SDFDisplacement().setFunction((vec) -> {
return -6F;
}).setSource(cave).setReplaceFunction(REPLACE1).fillRecursiveIgnore(world, pos, IGNORE);
BlocksHelper.setWithoutUpdate(world, pos, WATER);
MutableBlockPos mut = new MutableBlockPos().set(pos);
count = getYOnSurface(world, pos.getX(), pos.getZ()) - pos.getY();
for (int i = 0; i < count; i++) {
BlocksHelper.setWithoutUpdate(world, mut, WATER);
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlocksHelper.setWithoutUpdate(world, mut.relative(dir), WATER);
}
mut.setY(mut.getY() + 1);
}
for (int i = 0; i < 150; i++) {
mut.set(pos)
.move(MHelper.floor(random.nextGaussian() * 4 + 0.5),
-halfHeight - 10,
MHelper.floor(random.nextGaussian() * 4 + 0.5)
);
float distRaw = MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ());
int dist = MHelper.floor(6 - distRaw) + random.nextInt(2);
if (dist >= 0) {
state = world.getBlockState(mut);
while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.WATER_PLANT)) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.is(CommonBlockTags.GEN_END_STONES) && !world.getBlockState(mut.above())
.is(EndBlocks.HYDROTHERMAL_VENT)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
MHelper.shuffle(HORIZONTAL, random);
for (Direction dir : HORIZONTAL) {
BlockPos p = mut.relative(dir);
if (random.nextBoolean() && world.getBlockState(p).is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(
world,
p,
EndBlocks.TUBE_WORM.defaultBlockState()
.setValue(HorizontalDirectionalBlock.FACING, dir)
);
}
}
mut.setY(mut.getY() + 1);
}
state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState()
.setValue(HydrothermalVentBlock.ACTIVATED, distRaw < 2);
BlocksHelper.setWithoutUpdate(world, mut, state);
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
while (state.is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState());
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
}
}
}
}
for (int i = 0; i < 10; i++) {
mut.set(pos)
.move(MHelper.floor(random.nextGaussian() * 0.7 + 0.5),
-halfHeight - 10,
MHelper.floor(random.nextGaussian() * 0.7 + 0.5)
);
float distRaw = MHelper.length(mut.getX() - pos.getX(), mut.getZ() - pos.getZ());
int dist = MHelper.floor(6 - distRaw) + random.nextInt(2);
if (dist >= 0) {
state = world.getBlockState(mut);
while (state.is(Blocks.WATER)) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.is(CommonBlockTags.GEN_END_STONES)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
mut.setY(mut.getY() + 1);
}
state = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState()
.setValue(HydrothermalVentBlock.ACTIVATED, distRaw < 2);
BlocksHelper.setWithoutUpdate(world, mut, state);
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
while (state.is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState());
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
}
}
}
}
EndFeatures.SULPHURIC_LAKE.getFeature()
.place(new FeaturePlaceContext<>(Optional.empty(),
world,
chunkGenerator,
random,
pos,
null));
double distance = radius1 * 1.7;
BlockPos start = pos.offset(-distance, -halfHeight - 15 - distance, -distance);
BlockPos end = pos.offset(distance, -halfHeight - 5 + distance, distance);
BlockFixer.fixBlocks(world, start, end);
return true;
}
static {
REPLACE1 = (state) -> {
return state.isAir() || (state.is(CommonBlockTags.GEN_END_STONES));
};
REPLACE2 = (state) -> {
if (state.is(CommonBlockTags.GEN_END_STONES) || state.is(EndBlocks.HYDROTHERMAL_VENT) || state.is(EndBlocks.SULPHUR_CRYSTAL)) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = (state) -> {
return state.is(Blocks.WATER) || state.is(Blocks.CAVE_AIR) || state.is(EndBlocks.SULPHURIC_ROCK.stone) || state
.is(EndBlocks.BRIMSTONE);
};
}
}

View file

@ -0,0 +1,114 @@
package org.betterx.betterend.world.features.terrain;
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 com.mojang.math.Vector3f;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFRotation;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.operator.SDFUnion;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.registry.EndBlocks;
import java.util.ArrayList;
import java.util.List;
public class IceStarFeature extends DefaultFeature {
private final float minSize;
private final float maxSize;
private final int minCount;
private final int maxCount;
public IceStarFeature(float minSize, float maxSize, int minCount, int maxCount) {
this.minSize = minSize;
this.maxSize = maxSize;
this.minCount = minCount;
this.maxCount = maxCount;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
float size = MHelper.randRange(minSize, maxSize, random);
int count = MHelper.randRange(minCount, maxCount, random);
List<Vector3f> points = getFibonacciPoints(count);
SDF sdf = null;
SDF spike = new SDFCappedCone().setRadius1(3 + (size - 5) * 0.2F)
.setRadius2(0)
.setHeight(size)
.setBlock(EndBlocks.DENSE_SNOW);
spike = new SDFTranslate().setTranslate(0, size - 0.5F, 0).setSource(spike);
for (Vector3f point : points) {
SDF rotated = spike;
point = MHelper.normalize(point);
float angle = MHelper.angle(Vector3f.YP, point);
if (angle > 0.01F && angle < 3.14F) {
Vector3f axis = MHelper.normalize(MHelper.cross(Vector3f.YP, point));
rotated = new SDFRotation().setRotation(axis, angle).setSource(spike);
} else if (angle > 1) {
rotated = new SDFRotation().setRotation(Vector3f.YP, (float) Math.PI).setSource(spike);
}
sdf = (sdf == null) ? rotated : new SDFUnion().setSourceA(sdf).setSourceB(rotated);
}
int x1 = (pos.getX() >> 4) << 4;
int z1 = (pos.getZ() >> 4) << 4;
pos = new BlockPos(x1 + random.nextInt(16), MHelper.randRange(32, 128, random), z1 + random.nextInt(16));
final float ancientRadius = size * 0.7F;
final float denseRadius = size * 0.9F;
final float iceRadius = size < 7 ? size * 5 : size * 1.3F;
final float randScale = size * 0.3F;
final BlockPos center = pos;
final BlockState ice = EndBlocks.EMERALD_ICE.defaultBlockState();
final BlockState dense = EndBlocks.DENSE_EMERALD_ICE.defaultBlockState();
final BlockState ancient = EndBlocks.ANCIENT_EMERALD_ICE.defaultBlockState();
final SDF sdfCopy = sdf;
sdf.addPostProcess((info) -> {
BlockPos bpos = info.getPos();
float px = bpos.getX() - center.getX();
float py = bpos.getY() - center.getY();
float pz = bpos.getZ() - center.getZ();
float distance = MHelper.length(px, py, pz) + sdfCopy.getDistance(
px,
py,
pz
) * 0.4F + random.nextFloat() * randScale;
if (distance < ancientRadius) {
return ancient;
} else if (distance < denseRadius) {
return dense;
} else if (distance < iceRadius) {
return ice;
}
return info.getState();
}).fillRecursive(world, pos);
return true;
}
private List<Vector3f> getFibonacciPoints(int count) {
float max = count - 1;
List<Vector3f> result = new ArrayList<Vector3f>(count);
for (int i = 0; i < count; i++) {
float y = 1F - (i / max) * 2F;
float radius = (float) Math.sqrt(1F - y * y);
float theta = MHelper.PHI * i;
float x = (float) Math.cos(theta) * radius;
float z = (float) Math.sin(theta) * radius;
result.add(new Vector3f(x, y, z));
}
return result;
}
}

View file

@ -0,0 +1,76 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
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 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.SDFScale3D;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
public class ObsidianBoulderFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
pos = getPosOnSurface(
world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))
);
if (!world.getBlockState(pos.below()).is(CommonBlockTags.END_STONES)) {
return false;
}
int count = MHelper.randRange(1, 5, random);
for (int i = 0; i < count; i++) {
BlockPos p = getPosOnSurface(
world,
new BlockPos(pos.getX() + random.nextInt(16) - 8, pos.getY(), pos.getZ() + random.nextInt(16) - 8)
);
makeBoulder(world, p, random);
}
return true;
}
private void makeBoulder(WorldGenLevel world, BlockPos pos, RandomSource random) {
if (!world.getBlockState(pos.below()).is(CommonBlockTags.END_STONES)) {
return;
}
float radius = MHelper.randRange(1F, 5F, random);
SDF sphere = new SDFSphere().setRadius(radius).setBlock(Blocks.OBSIDIAN);
float sx = MHelper.randRange(0.7F, 1.3F, random);
float sy = MHelper.randRange(0.7F, 1.3F, random);
float sz = MHelper.randRange(0.7F, 1.3F, random);
sphere = new SDFScale3D().setScale(sx, sy, sz).setSource(sphere);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) (noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 1.5F);
}).setSource(sphere);
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.defaultBlockState();
sphere.addPostProcess((info) -> {
if (info.getStateUp().isAir() && random.nextFloat() > 0.1F) {
return mossy;
}
return info.getState();
}).setReplaceFunction((state) -> {
return state.getMaterial()
.isReplaceable() || state.is(CommonBlockTags.GEN_END_STONES) || state.getMaterial()
.equals(Material.PLANT);
}).fillRecursive(world, pos);
}
}

View file

@ -0,0 +1,74 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
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 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.SDFRotation;
import org.betterx.bclib.sdf.operator.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.sdf.primitive.SDFFlatland;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
public class ObsidianPillarBasementFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
pos = getPosOnSurface(
world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))
);
if (!world.getBlockState(pos.below(5)).is(CommonBlockTags.GEN_END_STONES)) {
return false;
}
float height = MHelper.randRange(10F, 35F, random);
float radius = MHelper.randRange(2F, 5F, random);
SDF pillar = new SDFCappedCone().setRadius1(radius)
.setRadius2(radius)
.setHeight(height * 0.5F)
.setBlock(Blocks.OBSIDIAN);
pillar = new SDFTranslate().setTranslate(0, height * 0.5F - 3, 0).setSource(pillar);
SDF cut = new SDFFlatland().setBlock(Blocks.OBSIDIAN);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
cut = new SDFDisplacement().setFunction((vec) -> {
return (float) (noise.eval(vec.x() * 0.2, vec.z() * 0.2) * 3);
}).setSource(cut);
Vector3f vec = MHelper.randomHorizontal(random);
float angle = random.nextFloat() * 0.5F + (float) Math.PI;
cut = new SDFRotation().setRotation(vec, angle).setSource(cut);
cut = new SDFTranslate().setTranslate(0, height * 0.7F - 3, 0).setSource(cut);
pillar = new SDFSubtraction().setSourceA(pillar).setSourceB(cut);
vec = MHelper.randomHorizontal(random);
angle = random.nextFloat() * 0.2F;
pillar = new SDFRotation().setRotation(vec, angle).setSource(pillar);
BlockState mossy = EndBlocks.MOSSY_OBSIDIAN.defaultBlockState();
pillar.addPostProcess((info) -> {
if (info.getStateUp().isAir() && random.nextFloat() > 0.1F) {
return mossy;
}
return info.getState();
}).setReplaceFunction((state) -> {
return state.getMaterial()
.isReplaceable() || state.is(CommonBlockTags.GEN_END_STONES) || state.getMaterial()
.equals(Material.PLANT);
}).fillRecursive(world, pos);
return true;
}
}

View file

@ -0,0 +1,76 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
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 org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFCoordModify;
import org.betterx.bclib.sdf.operator.SDFScale3D;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
public class OreLayerFeature extends DefaultFeature {
private static final SDFSphere SPHERE;
private static final SDFCoordModify NOISE;
private static final SDF FUNCTION;
private final BlockState state;
private final float radius;
private final int minY;
private final int maxY;
private OpenSimplexNoise noise;
public OreLayerFeature(BlockState state, float radius, int minY, int maxY) {
this.state = state;
this.radius = radius;
this.minY = minY;
this.maxY = maxY;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
float radius = this.radius * 0.5F;
int r = MHelper.floor(radius + 1);
int posX = MHelper.randRange(Math.max(r - 16, 0), Math.min(31 - r, 15), random) + pos.getX();
int posZ = MHelper.randRange(Math.max(r - 16, 0), Math.min(31 - r, 15), random) + pos.getZ();
int posY = MHelper.randRange(minY, maxY, random);
if (noise == null) {
noise = new OpenSimplexNoise(world.getSeed());
}
SPHERE.setRadius(radius).setBlock(state);
NOISE.setFunction((vec) -> {
double x = (vec.x() + pos.getX()) * 0.1;
double z = (vec.z() + pos.getZ()) * 0.1;
double offset = noise.eval(x, z);
vec.set(vec.x(), vec.y() + (float) offset * 8, vec.z());
});
FUNCTION.fillRecursive(world, new BlockPos(posX, posY, posZ));
return true;
}
static {
SPHERE = new SDFSphere();
NOISE = new SDFCoordModify();
SDF body = SPHERE;
body = new SDFScale3D().setScale(1, 0.2F, 1).setSource(body);
body = NOISE.setSource(body);
body.setReplaceFunction((state) -> {
return state.is(Blocks.END_STONE);
});
FUNCTION = body;
}
}

View file

@ -0,0 +1,41 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.features.DefaultFeature;
public class SingleBlockFeature extends DefaultFeature {
private final Block block;
public SingleBlockFeature(Block block) {
this.block = block;
}
@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.GEN_END_STONES)) {
return false;
}
BlockState state = block.defaultBlockState();
if (block.getStateDefinition().getProperty("waterlogged") != null) {
boolean waterlogged = !world.getFluidState(pos).isEmpty();
state = state.setValue(BlockStateProperties.WATERLOGGED, waterlogged);
}
BlocksHelper.setWithoutUpdate(world, pos, state);
return true;
}
}

View file

@ -0,0 +1,63 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.registry.EndBlocks;
public class SmaragdantCrystalFeature 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.GEN_END_STONES)) {
return false;
}
MutableBlockPos mut = new MutableBlockPos();
int count = MHelper.randRange(15, 30, random);
BlockState crystal = EndBlocks.SMARAGDANT_CRYSTAL.defaultBlockState();
BlockState shard = EndBlocks.SMARAGDANT_CRYSTAL_SHARD.defaultBlockState();
for (int i = 0; i < count; i++) {
mut.set(pos)
.move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5, MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(1.5F - MHelper.length(
mut.getX() - pos.getX(),
mut.getZ() - pos.getZ()
)) + random.nextInt(3);
if (dist > 0) {
BlockState state = world.getBlockState(mut);
for (int n = 0; n < 10 && state.isAir(); n++) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.is(CommonBlockTags.GEN_END_STONES) && !world.getBlockState(mut.above())
.is(crystal.getBlock())) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, crystal);
mut.setY(mut.getY() + 1);
}
boolean waterlogged = !world.getFluidState(mut).isEmpty();
BlocksHelper.setWithoutUpdate(
world,
mut,
shard.setValue(BlockStateProperties.WATERLOGGED, waterlogged)
);
}
}
}
return true;
}
}

View file

@ -0,0 +1,121 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
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.chunk.ChunkGenerator;
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.collect.Lists;
import org.betterx.bclib.api.biomes.BiomeAPI;
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.SDFSmoothUnion;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFSphere;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.world.biome.EndBiome;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
public class SpireFeature extends DefaultFeature {
protected static final Function<BlockState, Boolean> REPLACE;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
final ChunkGenerator chunkGenerator = featureConfig.chunkGenerator();
pos = getPosOnSurfaceWG(world, pos);
if (pos.getY() < 10 || !world.getBlockState(pos.below(3))
.is(CommonBlockTags.GEN_END_STONES) || !world.getBlockState(pos.below(6))
.is(CommonBlockTags.GEN_END_STONES)) {
return false;
}
SDF sdf = new SDFSphere().setRadius(MHelper.randRange(2, 3, random)).setBlock(Blocks.END_STONE);
int count = MHelper.randRange(3, 7, random);
for (int i = 0; i < count; i++) {
float rMin = (i * 1.3F) + 2.5F;
sdf = addSegment(sdf, MHelper.randRange(rMin, rMin + 1.5F, random), random);
}
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
sdf = new SDFDisplacement().setFunction((vec) -> {
return (float) (Math.abs(noise.eval(
vec.x() * 0.1,
vec.y() * 0.1,
vec.z() * 0.1
)) * 3F + Math.abs(noise.eval(vec.x() * 0.3,
vec.y() * 0.3 + 100,
vec.z() * 0.3)) * 1.3F);
}).setSource(sdf);
final BlockPos center = pos;
List<BlockPos> support = Lists.newArrayList();
sdf.setReplaceFunction(REPLACE).addPostProcess((info) -> {
if (info.getStateUp().isAir()) {
if (random.nextInt(16) == 0) {
support.add(info.getPos().above());
}
return EndBiome.findTopMaterial(world, info.getPos());
//return world.getBiome(info.getPos()).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
} else if (info.getState(Direction.UP, 3).isAir()) {
return EndBiome.findUnderMaterial(world, info.getPos());
// return world.getBiome(info.getPos())
// .getGenerationSettings()
// .getSurfaceBuilderConfig()
// .getUnderMaterial();
}
return info.getState();
}).fillRecursive(world, center);
support.forEach((bpos) -> {
if (BiomeAPI.getFromBiome(world.getBiome(bpos)) == EndBiomes.BLOSSOMING_SPIRES) {
EndFeatures.TENANEA_BUSH.getFeature()
.place(new FeaturePlaceContext<>(Optional.empty(),
world,
chunkGenerator,
random,
bpos,
null));
}
});
return true;
}
protected SDF addSegment(SDF sdf, float radius, RandomSource random) {
SDF sphere = new SDFSphere().setRadius(radius).setBlock(Blocks.END_STONE);
SDF offseted = new SDFTranslate().setTranslate(0, radius + random.nextFloat() * 0.25F * radius, 0)
.setSource(sdf);
return new SDFSmoothUnion().setRadius(radius * 0.5F).setSourceA(sphere).setSourceB(offseted);
}
static {
REPLACE = (state) -> {
if (state.is(CommonBlockTags.END_STONES)) {
return true;
}
if (state.getBlock() instanceof LeavesBlock) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,84 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.blocks.StalactiteBlock;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.features.DefaultFeature;
public class StalactiteFeature extends DefaultFeature {
private final boolean ceiling;
private final Block[] ground;
private final Block block;
public StalactiteFeature(boolean ceiling, Block block, Block... ground) {
this.ceiling = ceiling;
this.ground = ground;
this.block = block;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
if (!isGround(world.getBlockState(ceiling ? pos.above() : pos.below()).getBlock())) {
return false;
}
MutableBlockPos mut = new MutableBlockPos().set(pos);
int height = random.nextInt(16);
int dir = ceiling ? -1 : 1;
boolean stalagnate = false;
for (int i = 1; i <= height; i++) {
mut.setY(pos.getY() + i * dir);
BlockState state = world.getBlockState(mut);
if (!state.getMaterial().isReplaceable()) {
stalagnate = state.is(CommonBlockTags.GEN_END_STONES);
height = i;
break;
}
}
if (!stalagnate && height > 7) {
height = random.nextInt(8);
}
float center = height * 0.5F;
for (int i = 0; i < height; i++) {
mut.setY(pos.getY() + i * dir);
int size = stalagnate ? Mth.clamp((int) (Mth.abs(i - center) + 1), 1, 7) : height - i - 1;
boolean waterlogged = !world.getFluidState(mut).isEmpty();
BlockState base = block.defaultBlockState()
.setValue(StalactiteBlock.SIZE, size)
.setValue(BlockStateProperties.WATERLOGGED, waterlogged);
BlockState state = stalagnate ? base.setValue(
StalactiteBlock.IS_FLOOR,
dir > 0 ? i < center : i > center
) : base.setValue(StalactiteBlock.IS_FLOOR, dir > 0);
BlocksHelper.setWithoutUpdate(world, mut, state);
}
return true;
}
private boolean isGround(Block block) {
for (Block b : ground) {
if (b == block) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,96 @@
package org.betterx.betterend.world.features.terrain;
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.state.BlockState;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
public class SulphurHillFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
pos = getPosOnSurfaceWG(world, pos);
if (pos.getY() < 57 || pos.getY() > 70) {
return false;
}
int count = MHelper.randRange(5, 13, random);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
for (int i = 0; i < count; i++) {
int dist = count - i;
int px = pos.getX() + MHelper.floor(random.nextGaussian() * dist * 0.6 + 0.5);
int pz = pos.getZ() + MHelper.floor(random.nextGaussian() * dist * 0.6 + 0.5);
int py = getYOnSurface(world, px, pz);
if (py > 56 && py - pos.getY() <= count) {
makeCircle(world, new BlockPos(px, py, pz), noise, random);
}
}
return true;
}
private void makeCircle(WorldGenLevel world, BlockPos pos, OpenSimplexNoise noise, RandomSource random) {
int radius = MHelper.randRange(5, 9, random);
int min = -radius - 3;
int max = radius + 4;
MutableBlockPos mut = new MutableBlockPos();
BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.defaultBlockState();
BlockState brimstone = EndBlocks.BRIMSTONE.defaultBlockState().setValue(BlockProperties.ACTIVE, true);
for (int x = min; x < max; x++) {
int x2 = x * x;
int px = pos.getX() + x;
mut.setX(px);
for (int z = min; z < max; z++) {
int z2 = z * z;
int pz = pos.getZ() + z;
mut.setZ(pz);
double r1 = radius * (noise.eval(px * 0.1, pz * 0.1) * 0.2 + 0.8);
double r2 = r1 - 1.5;
double r3 = r1 - 3;
int d = x2 + z2;
mut.setY(pos.getY());
BlockState state = world.getBlockState(mut);
if (state.getMaterial().isReplaceable() || state.is(EndBlocks.HYDROTHERMAL_VENT)) {
if (d < r2 * r2) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.WATER);
mut.move(Direction.DOWN);
if (d < r3 * r3) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.WATER);
mut.move(Direction.DOWN);
}
BlocksHelper.setWithoutUpdate(world, mut, brimstone);
mut.move(Direction.DOWN);
state = world.getBlockState(mut);
int maxIt = MHelper.floor(10 - Math.sqrt(d)) + random.nextInt(1);
for (int i = 0; i < maxIt && state.getMaterial().isReplaceable(); i++) {
BlocksHelper.setWithoutUpdate(world, mut, rock);
mut.move(Direction.DOWN);
}
} else if (d < r1 * r1) {
BlocksHelper.setWithoutUpdate(world, mut, brimstone);
mut.move(Direction.DOWN);
state = world.getBlockState(mut);
int maxIt = MHelper.floor(10 - Math.sqrt(d)) + random.nextInt(1);
for (int i = 0; i < maxIt && state.getMaterial().isReplaceable(); i++) {
BlocksHelper.setWithoutUpdate(world, mut, rock);
mut.move(Direction.DOWN);
}
}
}
}
}
}
}

View file

@ -0,0 +1,222 @@
package org.betterx.betterend.world.features.terrain;
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.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
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.collect.Sets;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.EndBlockProperties;
import org.betterx.betterend.blocks.SulphurCrystalBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.util.BlockFixer;
import java.util.Set;
public class SulphuricCaveFeature extends DefaultFeature {
private static final BlockState CAVE_AIR = Blocks.CAVE_AIR.defaultBlockState();
private static final BlockState WATER = Blocks.WATER.defaultBlockState();
private static final Direction[] HORIZONTAL = BlocksHelper.makeHorizontal();
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
int radius = MHelper.randRange(10, 30, random);
int top = world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
MutableBlockPos bpos = new MutableBlockPos();
bpos.setX(pos.getX());
bpos.setZ(pos.getZ());
bpos.setY(top - 1);
BlockState state = world.getBlockState(bpos);
while (!state.is(CommonBlockTags.GEN_END_STONES) && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
if (bpos.getY() < 10) {
return false;
}
top = (int) (bpos.getY() - (radius * 1.3F + 5));
while (state.is(CommonBlockTags.GEN_END_STONES) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
int bottom = (int) (bpos.getY() + radius * 1.3F + 5);
if (top <= bottom) {
return false;
}
MutableBlockPos mut = new MutableBlockPos();
pos = new BlockPos(pos.getX(), MHelper.randRange(bottom, top, random), pos.getZ());
OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, pos.getX(), pos.getZ()));
int x1 = pos.getX() - radius - 5;
int z1 = pos.getZ() - radius - 5;
int x2 = pos.getX() + radius + 5;
int z2 = pos.getZ() + radius + 5;
int y1 = MHelper.floor(pos.getY() - (radius + 5) / 1.6);
int y2 = MHelper.floor(pos.getY() + (radius + 5) / 1.6);
double hr = radius * 0.75;
double nr = radius * 0.25;
Set<BlockPos> brimstone = Sets.newHashSet();
BlockState rock = EndBlocks.SULPHURIC_ROCK.stone.defaultBlockState();
int waterLevel = pos.getY() + MHelper.randRange(MHelper.floor(radius * 0.8), radius, random);
for (int x = x1; x <= x2; x++) {
int xsq = x - pos.getX();
xsq *= xsq;
mut.setX(x);
for (int z = z1; z <= z2; z++) {
int zsq = z - pos.getZ();
zsq *= zsq;
mut.setZ(z);
for (int y = y1; y <= y2; y++) {
int ysq = y - pos.getY();
ysq *= 1.6;
ysq *= ysq;
mut.setY(y);
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
double r2 = r + 5;
double dist = xsq + ysq + zsq;
if (dist < r * r) {
state = world.getBlockState(mut);
if (isReplaceable(state)) {
BlocksHelper.setWithoutUpdate(world, mut, y < waterLevel ? WATER : CAVE_AIR);
}
} else if (dist < r2 * r2) {
state = world.getBlockState(mut);
if (state.is(CommonBlockTags.GEN_END_STONES) || state.is(Blocks.AIR)) {
double v = noise.eval(x * 0.1, y * 0.1, z * 0.1) + noise.eval(
x * 0.03,
y * 0.03,
z * 0.03
) * 0.5;
if (v > 0.4) {
brimstone.add(mut.immutable());
} else {
BlocksHelper.setWithoutUpdate(world, mut, rock);
}
}
}
}
}
}
brimstone.forEach((blockPos) -> {
placeBrimstone(world, blockPos, random);
});
if (random.nextInt(4) == 0) {
int count = MHelper.randRange(5, 20, random);
for (int i = 0; i < count; i++) {
mut.set(pos)
.move(MHelper.floor(random.nextGaussian() * 2 + 0.5),
0,
MHelper.floor(random.nextGaussian() * 2 + 0.5)
);
int dist = MHelper.floor(3 - MHelper.length(
mut.getX() - pos.getX(),
mut.getZ() - pos.getZ()
)) + random.nextInt(2);
if (dist > 0) {
state = world.getBlockState(mut);
while (!state.getFluidState().isEmpty() || state.getMaterial().equals(Material.WATER_PLANT)) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.is(CommonBlockTags.GEN_END_STONES) && !world.getBlockState(mut.above())
.is(EndBlocks.HYDROTHERMAL_VENT)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
MHelper.shuffle(HORIZONTAL, random);
for (Direction dir : HORIZONTAL) {
BlockPos p = mut.relative(dir);
if (random.nextBoolean() && world.getBlockState(p).is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(
world,
p,
EndBlocks.TUBE_WORM.defaultBlockState()
.setValue(HorizontalDirectionalBlock.FACING, dir)
);
}
}
mut.setY(mut.getY() + 1);
}
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.HYDROTHERMAL_VENT);
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
while (state.is(Blocks.WATER)) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.VENT_BUBBLE_COLUMN.defaultBlockState());
world.scheduleTick(mut.immutable(),
EndBlocks.VENT_BUBBLE_COLUMN,
MHelper.randRange(8, 32, random));
mut.setY(mut.getY() + 1);
state = world.getBlockState(mut);
}
}
}
}
}
BlockFixer.fixBlocks(world, new BlockPos(x1, y1, z1), new BlockPos(x2, y2, z2));
return true;
}
private boolean isReplaceable(BlockState state) {
return state.is(CommonBlockTags.GEN_END_STONES) || state.is(EndBlocks.HYDROTHERMAL_VENT) || state.is(EndBlocks.VENT_BUBBLE_COLUMN) || state
.is(EndBlocks.SULPHUR_CRYSTAL) || state.getMaterial().isReplaceable() || state.getMaterial()
.equals(Material.PLANT) || state
.getMaterial()
.equals(Material.WATER_PLANT) || state.getMaterial().equals(Material.LEAVES);
}
private void placeBrimstone(WorldGenLevel world, BlockPos pos, RandomSource random) {
BlockState state = getBrimstone(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, state);
if (state.getValue(EndBlockProperties.ACTIVE)) {
makeShards(world, pos, random);
}
}
private BlockState getBrimstone(WorldGenLevel world, BlockPos pos) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.relative(dir)).is(Blocks.WATER)) {
return EndBlocks.BRIMSTONE.defaultBlockState().setValue(EndBlockProperties.ACTIVE, true);
}
}
return EndBlocks.BRIMSTONE.defaultBlockState();
}
private void makeShards(WorldGenLevel world, BlockPos pos, RandomSource random) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
BlockPos side;
if (random.nextInt(16) == 0 && world.getBlockState((side = pos.relative(dir))).is(Blocks.WATER)) {
BlockState state = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState()
.setValue(SulphurCrystalBlock.WATERLOGGED, true)
.setValue(SulphurCrystalBlock.FACING, dir)
.setValue(SulphurCrystalBlock.AGE, random.nextInt(3));
BlocksHelper.setWithoutUpdate(world, side, state);
}
}
}
}

View file

@ -0,0 +1,211 @@
package org.betterx.betterend.world.features.terrain;
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.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.Fluids;
import com.google.common.collect.Sets;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.EndBlockProperties;
import org.betterx.betterend.blocks.SulphurCrystalBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.util.GlobalState;
import java.util.Set;
public class SulphuricLakeFeature extends DefaultFeature {
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(15152);
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
BlockPos blockPos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
blockPos = getPosOnSurfaceWG(world, blockPos);
if (blockPos.getY() < 57) {
return false;
}
final RandomSource random = featureConfig.random();
final MutableBlockPos POS = GlobalState.stateForThread().POS;
double radius = MHelper.randRange(10.0, 20.0, random);
int dist2 = MHelper.floor(radius * 1.5);
int minX = blockPos.getX() - dist2;
int maxX = blockPos.getX() + dist2;
int minZ = blockPos.getZ() - dist2;
int maxZ = blockPos.getZ() + dist2;
Set<BlockPos> brimstone = Sets.newHashSet();
for (int x = minX; x <= maxX; x++) {
POS.setX(x);
int x2 = x - blockPos.getX();
x2 *= x2;
for (int z = minZ; z <= maxZ; z++) {
POS.setZ(z);
int z2 = z - blockPos.getZ();
z2 *= z2;
double r = radius * (NOISE.eval(x * 0.2, z * 0.2) * 0.25 + 0.75);
double r2 = r * 1.5;
r *= r;
r2 *= r2;
int dist = x2 + z2;
if (dist <= r) {
POS.setY(getYOnSurface(world, x, z) - 1);
if (world.getBlockState(POS).is(CommonBlockTags.GEN_END_STONES)) {
if (isBorder(world, POS)) {
if (random.nextInt(8) > 0) {
brimstone.add(POS.immutable());
if (random.nextBoolean()) {
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.below(2));
}
}
} else {
if (!isAbsoluteBorder(world, POS)) {
BlocksHelper.setWithoutUpdate(world, POS, Blocks.WATER);
//world.setBlock(blockPos, Blocks.WATER.defaultBlockState(), 2);
world.scheduleTick(POS, Fluids.WATER, 0);
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.below(2));
if (random.nextBoolean()) {
brimstone.add(POS.below(3));
}
}
} else {
brimstone.add(POS.immutable());
if (random.nextBoolean()) {
brimstone.add(POS.below());
}
}
}
} else {
BlocksHelper.setWithoutUpdate(world, POS, Blocks.WATER);
brimstone.remove(POS);
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos offseted = POS.relative(dir);
if (world.getBlockState(offseted).is(CommonBlockTags.GEN_END_STONES)) {
brimstone.add(offseted);
}
}
if (isDeepWater(world, POS)) {
BlocksHelper.setWithoutUpdate(world, POS.move(Direction.DOWN), Blocks.WATER);
brimstone.remove(POS);
for (Direction dir : BlocksHelper.HORIZONTAL) {
BlockPos offseted = POS.relative(dir);
if (world.getBlockState(offseted).is(CommonBlockTags.GEN_END_STONES)) {
brimstone.add(offseted);
}
}
}
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.below(2));
if (random.nextBoolean()) {
brimstone.add(POS.below(3));
}
}
}
}
} else if (dist < r2) {
POS.setY(getYOnSurface(world, x, z) - 1);
if (world.getBlockState(POS).is(CommonBlockTags.GEN_END_STONES)) {
brimstone.add(POS.immutable());
if (random.nextBoolean()) {
brimstone.add(POS.below());
if (random.nextBoolean()) {
brimstone.add(POS.below(2));
}
}
}
}
}
}
brimstone.forEach((bpos) -> {
placeBrimstone(world, bpos, random);
});
return true;
}
private boolean isBorder(WorldGenLevel world, BlockPos pos) {
int y = pos.getY() + 1;
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (getYOnSurface(world, pos.getX() + dir.getStepX(), pos.getZ() + dir.getStepZ()) < y) {
return true;
}
}
return false;
}
private boolean isAbsoluteBorder(WorldGenLevel world, BlockPos pos) {
int y = pos.getY() - 2;
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (getYOnSurface(world, pos.getX() + dir.getStepX() * 3, pos.getZ() + dir.getStepZ() * 3) < y) {
return true;
}
}
return false;
}
private boolean isDeepWater(WorldGenLevel world, BlockPos pos) {
int y = pos.getY() + 1;
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (getYOnSurface(world, pos.getX() + dir.getStepX(), pos.getZ() + dir.getStepZ()) < y || getYOnSurface(
world,
pos.getX() + dir.getStepX() * 2,
pos.getZ() + dir.getStepZ() * 2
) < y || getYOnSurface(
world,
pos.getX() + dir.getStepX() * 3,
pos.getZ() + dir.getStepZ() * 3) < y) {
return false;
}
}
return true;
}
private void placeBrimstone(WorldGenLevel world, BlockPos pos, RandomSource random) {
BlockState state = getBrimstone(world, pos);
BlocksHelper.setWithoutUpdate(world, pos, state);
if (state.getValue(EndBlockProperties.ACTIVE)) {
makeShards(world, pos, random);
}
}
private BlockState getBrimstone(WorldGenLevel world, BlockPos pos) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (world.getBlockState(pos.relative(dir)).is(Blocks.WATER)) {
return EndBlocks.BRIMSTONE.defaultBlockState().setValue(EndBlockProperties.ACTIVE, true);
}
}
return EndBlocks.BRIMSTONE.defaultBlockState();
}
private void makeShards(WorldGenLevel world, BlockPos pos, RandomSource random) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
BlockPos side;
if (random.nextInt(16) == 0 && world.getBlockState((side = pos.relative(dir))).is(Blocks.WATER)) {
BlockState state = EndBlocks.SULPHUR_CRYSTAL.defaultBlockState()
.setValue(SulphurCrystalBlock.WATERLOGGED, true)
.setValue(SulphurCrystalBlock.FACING, dir)
.setValue(SulphurCrystalBlock.AGE, random.nextInt(3));
BlocksHelper.setWithoutUpdate(world, side, state);
}
}
}
}

View file

@ -0,0 +1,62 @@
package org.betterx.betterend.world.features.terrain;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
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 org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.blocks.HydrothermalVentBlock;
import org.betterx.betterend.registry.EndBlocks;
public class SurfaceVentFeature extends DefaultFeature {
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
pos = getPosOnSurface(
world,
new BlockPos(pos.getX() + random.nextInt(16), pos.getY(), pos.getZ() + random.nextInt(16))
);
if (!world.getBlockState(pos.below(3)).is(CommonBlockTags.GEN_END_STONES)) {
return false;
}
MutableBlockPos mut = new MutableBlockPos();
int count = MHelper.randRange(15, 30, random);
BlockState vent = EndBlocks.HYDROTHERMAL_VENT.defaultBlockState()
.setValue(HydrothermalVentBlock.WATERLOGGED, false);
for (int i = 0; i < count; i++) {
mut.set(pos)
.move(MHelper.floor(random.nextGaussian() * 2 + 0.5), 5, MHelper.floor(random.nextGaussian() * 2 + 0.5));
int dist = MHelper.floor(2 - MHelper.length(
mut.getX() - pos.getX(),
mut.getZ() - pos.getZ()
)) + random.nextInt(2);
if (dist > 0) {
BlockState state = world.getBlockState(mut);
for (int n = 0; n < 10 && state.isAir(); n++) {
mut.setY(mut.getY() - 1);
state = world.getBlockState(mut);
}
if (state.is(CommonBlockTags.GEN_END_STONES) && !world.getBlockState(mut.above())
.is(EndBlocks.HYDROTHERMAL_VENT)) {
for (int j = 0; j <= dist; j++) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.SULPHURIC_ROCK.stone);
mut.setY(mut.getY() + 1);
}
BlocksHelper.setWithoutUpdate(world, mut, vent);
}
}
}
return true;
}
}

View file

@ -0,0 +1,83 @@
package org.betterx.betterend.world.features.terrain;
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.Block;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import com.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFCoordModify;
import org.betterx.bclib.sdf.operator.SDFDisplacement;
import org.betterx.bclib.sdf.operator.SDFRotation;
import org.betterx.bclib.sdf.operator.SDFUnion;
import org.betterx.bclib.sdf.primitive.SDFTorus;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.noise.OpenSimplexNoise;
public class ThinArchFeature extends DefaultFeature {
private final Block block;
public ThinArchFeature(Block block) {
this.block = block;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featurePlaceContext) {
final WorldGenLevel world = featurePlaceContext.level();
BlockPos origin = featurePlaceContext.origin();
RandomSource random = featurePlaceContext.random();
BlockPos pos = getPosOnSurfaceWG(world,
new BlockPos((origin.getX() & 0xFFFFFFF0) | 7,
0,
(origin.getZ() & 0xFFFFFFF0) | 7));
if (!world.getBlockState(pos.below(5)).is(CommonBlockTags.GEN_END_STONES)) {
return false;
}
SDF sdf = null;
float bigRadius = MHelper.randRange(15F, 20F, random);
float variation = bigRadius * 0.3F;
int count = MHelper.randRange(2, 4, random);
for (int i = 0; i < count; i++) {
float smallRadius = MHelper.randRange(0.6F, 1.3F, random);
SDF arch = new SDFTorus().setBigRadius(bigRadius - random.nextFloat() * variation)
.setSmallRadius(smallRadius)
.setBlock(block);
float angle = (i - count * 0.5F) * 0.3F + random.nextFloat() * 0.05F + (float) Math.PI * 0.5F;
arch = new SDFRotation().setRotation(Vector3f.XP, angle).setSource(arch);
sdf = sdf == null ? arch : new SDFUnion().setSourceA(sdf).setSourceB(arch);
}
sdf = new SDFRotation().setRotation(MHelper.randomHorizontal(random), random.nextFloat() * MHelper.PI2)
.setSource(sdf);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
sdf = new SDFCoordModify().setFunction(vec -> {
float dx = (float) noise.eval(vec.y() * 0.02, vec.z() * 0.02);
float dy = (float) noise.eval(vec.x() * 0.02, vec.z() * 0.02);
float dz = (float) noise.eval(vec.x() * 0.02, vec.y() * 0.02);
vec.add(dx * 10, dy * 10, dz * 10);
}).setSource(sdf);
sdf = new SDFDisplacement().setFunction(vec -> {
float offset = vec.y() / bigRadius - 0.5F;
return Mth.clamp(offset * 3, -10F, 0F);
}).setSource(sdf);
float side = (bigRadius + 2.5F) * 2;
if (side > 47) {
side = 47;
}
sdf.fillArea(world, pos, AABB.ofSize(Vec3.atCenterOf(pos), side, side, side));
return true;
}
}

View file

@ -0,0 +1,149 @@
package org.betterx.betterend.world.features.terrain.caves;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
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.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import com.google.common.collect.Sets;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.betterend.util.BlockFixer;
import org.betterx.betterend.world.biome.cave.EndCaveBiome;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
public class CaveChunkPopulatorFeature extends DefaultFeature {
private final Supplier<EndCaveBiome> supplier;
public CaveChunkPopulatorFeature(Supplier<EndCaveBiome> biome) {
this.supplier = biome;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
Set<BlockPos> floorPositions = Sets.newHashSet();
Set<BlockPos> ceilPositions = Sets.newHashSet();
int sx = (pos.getX() >> 4) << 4;
int sz = (pos.getZ() >> 4) << 4;
MutableBlockPos min = new MutableBlockPos().set(pos);
MutableBlockPos max = new MutableBlockPos().set(pos);
fillSets(sx, sz, world.getChunk(pos), floorPositions, ceilPositions, min, max);
EndCaveBiome biome = supplier.get();
BlockState surfaceBlock = Blocks.END_STONE.defaultBlockState(); //biome.getBiome().getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
placeFloor(world, biome, floorPositions, random, surfaceBlock);
placeCeil(world, biome, ceilPositions, random);
BlockFixer.fixBlocks(world, min, max);
return true;
}
protected void fillSets(int sx,
int sz,
ChunkAccess chunk,
Set<BlockPos> floorPositions,
Set<BlockPos> ceilPositions,
MutableBlockPos min,
MutableBlockPos max) {
MutableBlockPos mut = new MutableBlockPos();
MutableBlockPos mut2 = new MutableBlockPos();
MutableBlockPos mut3 = new MutableBlockPos();
for (int x = 0; x < 16; x++) {
mut.setX(x);
mut2.setX(x);
for (int z = 0; z < 16; z++) {
mut.setZ(z);
mut2.setZ(z);
mut2.setY(0);
for (int y = 1; y < chunk.getMaxBuildHeight(); y++) {
mut.setY(y);
BlockState top = chunk.getBlockState(mut);
BlockState bottom = chunk.getBlockState(mut2);
if (top.isAir() && (bottom.is(CommonBlockTags.GEN_END_STONES) || bottom.is(Blocks.STONE))) {
mut3.set(mut2).move(sx, 0, sz);
floorPositions.add(mut3.immutable());
updateMin(mut3, min);
updateMax(mut3, max);
} else if (bottom.isAir() && (top.is(CommonBlockTags.GEN_END_STONES) || top.is(Blocks.STONE))) {
mut3.set(mut).move(sx, 0, sz);
ceilPositions.add(mut3.immutable());
updateMin(mut3, min);
updateMax(mut3, max);
}
mut2.setY(y);
}
}
}
}
private void updateMin(BlockPos pos, MutableBlockPos min) {
if (pos.getX() < min.getX()) {
min.setX(pos.getX());
}
if (pos.getY() < min.getY()) {
min.setY(pos.getY());
}
if (pos.getZ() < min.getZ()) {
min.setZ(pos.getZ());
}
}
private void updateMax(BlockPos pos, MutableBlockPos max) {
if (pos.getX() > max.getX()) {
max.setX(pos.getX());
}
if (pos.getY() > max.getY()) {
max.setY(pos.getY());
}
if (pos.getZ() > max.getZ()) {
max.setZ(pos.getZ());
}
}
protected void placeFloor(WorldGenLevel world,
EndCaveBiome biome,
Set<BlockPos> floorPositions,
RandomSource random,
BlockState surfaceBlock) {
float density = biome.getFloorDensity();
floorPositions.forEach((pos) -> {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) {
feature.place(new FeaturePlaceContext<>(Optional.empty(), world, null, random, pos.above(), null));
}
}
});
}
protected void placeCeil(WorldGenLevel world,
EndCaveBiome biome,
Set<BlockPos> ceilPositions,
RandomSource random) {
float density = biome.getCeilDensity();
ceilPositions.forEach((pos) -> {
BlockState ceilBlock = biome.getCeil(pos);
if (ceilBlock != null) {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
}
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) {
feature.place(new FeaturePlaceContext<>(Optional.empty(), world, null, random, pos.below(), null));
}
}
});
}
}

View file

@ -0,0 +1,270 @@
package org.betterx.betterend.world.features.terrain.caves;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.Vec3i;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.biomes.BCLBiome;
import org.betterx.bclib.world.features.DefaultFeature;
import org.betterx.bclib.world.generator.BiomePicker;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.util.BlockFixer;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.biome.cave.EndCaveBiome;
import java.util.List;
import java.util.Optional;
import java.util.Set;
public abstract class EndCaveFeature extends DefaultFeature {
protected static final BlockState CAVE_AIR = Blocks.CAVE_AIR.defaultBlockState();
protected static final BlockState END_STONE = Blocks.END_STONE.defaultBlockState();
protected static final BlockState WATER = Blocks.WATER.defaultBlockState();
private static final Vec3i[] SPHERE;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
if (pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 2500) {
return false;
}
if (biomeMissingCaves(world, pos)) {
return false;
}
int radius = MHelper.randRange(10, 30, random);
BlockPos center = findPos(world, pos, radius, random);
if (center == null) {
return false;
}
BiomePicker.ActualBiome biome = EndBiomes.getCaveBiome(pos.getX(), pos.getZ());
Set<BlockPos> caveBlocks = generate(world, center, radius, random);
if (!caveBlocks.isEmpty()) {
if (biome != null) {
setBiomes(world, biome, caveBlocks);
Set<BlockPos> floorPositions = Sets.newConcurrentHashSet();
Set<BlockPos> ceilPositions = Sets.newConcurrentHashSet();
caveBlocks.parallelStream().forEach((bpos) -> {
if (world.getBlockState(bpos).getMaterial().isReplaceable()) {
BlockPos side = bpos.below();
if (world.getBlockState(side).is(CommonBlockTags.GEN_END_STONES)) {
floorPositions.add(side);
}
side = bpos.above();
if (world.getBlockState(side).is(CommonBlockTags.GEN_END_STONES)) {
ceilPositions.add(side);
}
}
});
BlockState surfaceBlock = EndBiome.findTopMaterial(biome.bclBiome);
placeFloor(world, (EndCaveBiome) biome.bclBiome, floorPositions, random, surfaceBlock);
placeCeil(world, (EndCaveBiome) biome.bclBiome, ceilPositions, random);
placeWalls(world, (EndCaveBiome) biome.bclBiome, caveBlocks, random);
}
fixBlocks(world, caveBlocks);
}
return true;
}
protected abstract Set<BlockPos> generate(WorldGenLevel world, BlockPos center, int radius, RandomSource random);
protected void placeFloor(WorldGenLevel world,
EndCaveBiome biome,
Set<BlockPos> floorPositions,
RandomSource random,
BlockState surfaceBlock) {
float density = biome.getFloorDensity();
floorPositions.forEach((pos) -> {
if (!surfaceBlock.is(Blocks.END_STONE)) {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
}
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) {
feature.place(new FeaturePlaceContext<>(Optional.empty(), world, null, random, pos.above(), null));
}
}
});
}
protected void placeCeil(WorldGenLevel world,
EndCaveBiome biome,
Set<BlockPos> ceilPositions,
RandomSource random) {
float density = biome.getCeilDensity();
ceilPositions.forEach((pos) -> {
BlockState ceilBlock = biome.getCeil(pos);
if (ceilBlock != null) {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
}
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) {
feature.place(new FeaturePlaceContext<>(Optional.empty(), world, null, random, pos.below(), null));
}
}
});
}
protected void placeWalls(WorldGenLevel world, EndCaveBiome biome, Set<BlockPos> positions, RandomSource random) {
Set<BlockPos> placed = Sets.newHashSet();
positions.forEach(pos -> {
if (random.nextInt(4) == 0 && hasOpenSide(pos, positions)) {
BlockState wallBlock = biome.getWall(pos);
if (wallBlock != null) {
for (Vec3i offset : SPHERE) {
BlockPos wallPos = pos.offset(offset);
if (!positions.contains(wallPos) && !placed.contains(wallPos) && world.getBlockState(wallPos)
.is(CommonBlockTags.GEN_END_STONES)) {
wallBlock = biome.getWall(wallPos);
BlocksHelper.setWithoutUpdate(world, wallPos, wallBlock);
placed.add(wallPos);
}
}
}
}
});
}
private boolean hasOpenSide(BlockPos pos, Set<BlockPos> positions) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (!positions.contains(pos.relative(dir))) {
return true;
}
}
return false;
}
protected void setBiomes(WorldGenLevel world, BiomePicker.ActualBiome biome, Set<BlockPos> blocks) {
blocks.forEach((pos) -> setBiome(world, pos, biome));
}
protected void setBiome(WorldGenLevel world, BlockPos pos, BiomePicker.ActualBiome biome) {
BiomeAPI.setBiome(world, pos, biome.biome);
}
private BlockPos findPos(WorldGenLevel world, BlockPos pos, int radius, RandomSource random) {
int top = world.getHeight(Heightmap.Types.WORLD_SURFACE_WG, pos.getX(), pos.getZ());
MutableBlockPos bpos = new MutableBlockPos();
bpos.setX(pos.getX());
bpos.setZ(pos.getZ());
bpos.setY(top - 1);
BlockState state = world.getBlockState(bpos);
while (!state.is(CommonBlockTags.GEN_END_STONES) && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
if (bpos.getY() < 10) {
return null;
}
top = (int) (bpos.getY() - (radius * 1.3F + 5));
while (state.is(CommonBlockTags.GEN_END_STONES) || !state.getFluidState().isEmpty() && bpos.getY() > 5) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
int bottom = (int) (bpos.getY() + radius * 1.3F + 5);
if (top <= bottom) {
return null;
}
return new BlockPos(pos.getX(), MHelper.randRange(bottom, top, random), pos.getZ());
}
protected void fixBlocks(WorldGenLevel world, Set<BlockPos> caveBlocks) {
BlockPos pos = caveBlocks.iterator().next();
MutableBlockPos start = new MutableBlockPos().set(pos);
MutableBlockPos end = new MutableBlockPos().set(pos);
caveBlocks.forEach((bpos) -> {
if (bpos.getX() < start.getX()) {
start.setX(bpos.getX());
}
if (bpos.getX() > end.getX()) {
end.setX(bpos.getX());
}
if (bpos.getY() < start.getY()) {
start.setY(bpos.getY());
}
if (bpos.getY() > end.getY()) {
end.setY(bpos.getY());
}
if (bpos.getZ() < start.getZ()) {
start.setZ(bpos.getZ());
}
if (bpos.getZ() > end.getZ()) {
end.setZ(bpos.getZ());
}
});
BlockFixer.fixBlocks(world, start.offset(-2, -2, -2), end.offset(2, 2, 2));
}
protected boolean isWaterNear(WorldGenLevel world, BlockPos pos) {
for (Direction dir : BlocksHelper.DIRECTIONS) {
if (!world.getFluidState(pos.relative(dir, 5)).isEmpty()) {
return true;
}
}
return false;
}
protected boolean biomeMissingCaves(WorldGenLevel world, BlockPos pos) {
for (int x = -2; x < 3; x++) {
for (int z = -2; z < 3; z++) {
Holder<Biome> biome = world.getBiome(pos.offset(x << 4, 0, z << 4));
BCLBiome endBiome = BiomeAPI.getFromBiome(biome);
boolean hasCaves = endBiome.getCustomData("has_caves", true);
if (!hasCaves && BiomeAPI.wasRegisteredAsEndLandBiome(endBiome.getID())) {
return true;
}
}
}
return false;
}
static {
List<Vec3i> prePos = Lists.newArrayList();
int radius = 5;
int r2 = radius * radius;
for (int x = -radius; x <= radius; x++) {
int x2 = x * x;
for (int y = -radius; y <= radius; y++) {
int y2 = y * y;
for (int z = -radius; z <= radius; z++) {
int z2 = z * z;
if (x2 + y2 + z2 < r2) {
prePos.add(new Vec3i(x, y, z));
}
}
}
}
SPHERE = prePos.toArray(new Vec3i[]{});
}
}

View file

@ -0,0 +1,83 @@
package org.betterx.betterend.world.features.terrain.caves;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import com.google.common.collect.Sets;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import org.betterx.betterend.noise.OpenSimplexNoise;
import java.util.Set;
import java.util.stream.IntStream;
public class RoundCaveFeature extends EndCaveFeature {
@Override
protected Set<BlockPos> generate(WorldGenLevel world, BlockPos center, int radius, RandomSource random) {
OpenSimplexNoise noise = new OpenSimplexNoise(MHelper.getSeed(534, center.getX(), center.getZ()));
int x1 = center.getX() - radius - 5;
int z1 = center.getZ() - radius - 5;
int x2 = center.getX() + radius + 5;
int z2 = center.getZ() + radius + 5;
int y1 = MHelper.floor(center.getY() - (radius + 5) / 1.6);
int y2 = MHelper.floor(center.getY() + (radius + 5) / 1.6);
double hr = radius * 0.75;
double nr = radius * 0.25;
int dx = x2 - x1 + 1;
int dz = z2 - z1 + 1;
int count = dx * dz;
Set<BlockPos> blocks = Sets.newConcurrentHashSet();
IntStream.range(0, count).parallel().forEach(index -> {
MutableBlockPos bpos = new MutableBlockPos();
int x = (index % dx) + x1;
int z = (index / dx) + z1;
bpos.setX(x);
bpos.setZ(z);
int xsq = MHelper.sqr(x - center.getX());
int zsq = MHelper.sqr(z - center.getZ());
int dxz = xsq + zsq;
BlockState state;
for (int y = y1; y <= y2; y++) {
int ysq = (int) MHelper.sqr((y - center.getY()) * 1.6);
double r = noise.eval(x * 0.1, y * 0.1, z * 0.1) * nr + hr;
double dist = dxz + ysq;
if (dist < r * r) {
bpos.setY(y);
state = world.getBlockState(bpos);
if (isReplaceable(state) && !isWaterNear(world, bpos)) {
blocks.add(bpos.immutable());
while (state.getMaterial().equals(Material.LEAVES)) {
bpos.setY(bpos.getY() + 1);
state = world.getBlockState(bpos);
}
bpos.setY(y - 1);
while (state.getMaterial().equals(Material.LEAVES)) {
bpos.setY(bpos.getY() - 1);
state = world.getBlockState(bpos);
}
}
}
}
});
blocks.forEach(bpos -> BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR));
return blocks;
}
private boolean isReplaceable(BlockState state) {
return state.is(CommonBlockTags.GEN_END_STONES) ||
state.getMaterial().isReplaceable() ||
state.getMaterial().equals(Material.PLANT) ||
state.getMaterial().equals(Material.LEAVES);
}
}

View file

@ -0,0 +1,250 @@
package org.betterx.betterend.world.features.terrain.caves;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.util.Mth;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.levelgen.Heightmap.Types;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.world.biomes.BCLBiome;
import org.betterx.bclib.world.generator.BiomePicker;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBiomes;
import org.betterx.betterend.world.biome.EndBiome;
import org.betterx.betterend.world.biome.cave.EndCaveBiome;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.IntStream;
public class TunelCaveFeature extends EndCaveFeature {
private Set<BlockPos> generate(WorldGenLevel world, BlockPos center, RandomSource random) {
int cx = center.getX() >> 4;
int cz = center.getZ() >> 4;
if ((long) cx * (long) cx + (long) cz + (long) cz < 256) {
return Sets.newHashSet();
}
int x1 = cx << 4;
int z1 = cz << 4;
int x2 = x1 + 16;
int z2 = z1 + 16;
RandomSource rand = new LegacyRandomSource(world.getSeed());
OpenSimplexNoise noiseH = new OpenSimplexNoise(rand.nextInt());
OpenSimplexNoise noiseV = new OpenSimplexNoise(rand.nextInt());
OpenSimplexNoise noiseD = new OpenSimplexNoise(rand.nextInt());
Set<BlockPos> positions = Sets.newConcurrentHashSet();
float a = hasCaves(world, new BlockPos(x1, 0, z1)) ? 1F : 0F;
float b = hasCaves(world, new BlockPos(x2, 0, z1)) ? 1F : 0F;
float c = hasCaves(world, new BlockPos(x1, 0, z2)) ? 1F : 0F;
float d = hasCaves(world, new BlockPos(x2, 0, z2)) ? 1F : 0F;
ChunkAccess chunk = world.getChunk(cx, cz);
IntStream.range(0, 256).parallel().forEach(index -> {
MutableBlockPos pos = new MutableBlockPos();
int x = index & 15;
int z = index >> 4;
int wheight = chunk.getHeight(Types.WORLD_SURFACE_WG, x, z);
float dx = x / 16F;
float dz = z / 16F;
pos.setX(x + x1);
pos.setZ(z + z1);
float da = Mth.lerp(dx, a, b);
float db = Mth.lerp(dx, c, d);
float density = 1 - Mth.lerp(dz, da, db);
if (density < 0.5) {
for (int y = 0; y < wheight; y++) {
pos.setY(y);
float gradient = 1 - Mth.clamp((wheight - y) * 0.1F, 0F, 1F);
if (gradient > 0.5) {
break;
}
float val = Mth.abs((float) noiseH.eval(pos.getX() * 0.02, y * 0.01, pos.getZ() * 0.02));
float vert = Mth.sin((y + (float) noiseV.eval(
pos.getX() * 0.01,
pos.getZ() * 0.01
) * 20) * 0.1F) * 0.9F;
float dist = (float) noiseD.eval(pos.getX() * 0.1, y * 0.1, pos.getZ() * 0.1) * 0.12F;
val = (val + vert * vert + dist) + density + gradient;
if (val < 0.15 && world.getBlockState(pos).is(CommonBlockTags.GEN_END_STONES) && noWaterNear(world,
pos)) {
positions.add(pos.immutable());
}
}
}
});
positions.forEach(bpos -> BlocksHelper.setWithoutUpdate(world, bpos, CAVE_AIR));
return positions;
}
private boolean noWaterNear(WorldGenLevel world, BlockPos pos) {
BlockPos above1 = pos.above();
BlockPos above2 = pos.above(2);
if (!world.getFluidState(above1).isEmpty() || !world.getFluidState(above2).isEmpty()) {
return false;
}
for (Direction dir : BlocksHelper.HORIZONTAL) {
if (!world.getFluidState(above1.relative(dir)).isEmpty()) {
return false;
}
if (!world.getFluidState(above2.relative(dir)).isEmpty()) {
return false;
}
}
return true;
}
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
if (pos.getX() * pos.getX() + pos.getZ() * pos.getZ() <= 2500) {
return false;
}
if (biomeMissingCaves(world, pos)) {
return false;
}
Set<BlockPos> caveBlocks = generate(world, pos, random);
if (caveBlocks.isEmpty()) {
return false;
}
Map<BiomePicker.ActualBiome, Set<BlockPos>> floorSets = Maps.newHashMap();
Map<BiomePicker.ActualBiome, Set<BlockPos>> ceilSets = Maps.newHashMap();
MutableBlockPos mut = new MutableBlockPos();
Set<BlockPos> remove = Sets.newHashSet();
caveBlocks.forEach((bpos) -> {
mut.set(bpos);
BiomePicker.ActualBiome bio = EndBiomes.getCaveBiome(bpos.getX(), bpos.getZ());
int height = world.getHeight(Types.WORLD_SURFACE, bpos.getX(), bpos.getZ());
if (mut.getY() >= height) {
remove.add(bpos);
} else if (world.getBlockState(mut).getMaterial().isReplaceable()) {
mut.setY(bpos.getY() - 1);
if (world.getBlockState(mut).is(CommonBlockTags.GEN_END_STONES)) {
Set<BlockPos> floorPositions = floorSets.get(bio);
if (floorPositions == null) {
floorPositions = Sets.newHashSet();
floorSets.put(bio, floorPositions);
}
floorPositions.add(mut.immutable());
}
mut.setY(bpos.getY() + 1);
if (world.getBlockState(mut).is(CommonBlockTags.GEN_END_STONES)) {
Set<BlockPos> ceilPositions = ceilSets.get(bio);
if (ceilPositions == null) {
ceilPositions = Sets.newHashSet();
ceilSets.put(bio, ceilPositions);
}
ceilPositions.add(mut.immutable());
}
setBiome(world, bpos, bio);
}
});
caveBlocks.removeAll(remove);
if (caveBlocks.isEmpty()) {
return true;
}
floorSets.forEach((biome, floorPositions) -> {
BlockState surfaceBlock = EndBiome.findTopMaterial(biome.bclBiome);
placeFloor(world, (EndCaveBiome) biome.bclBiome, floorPositions, random, surfaceBlock);
});
ceilSets.forEach((biome, ceilPositions) -> {
placeCeil(world, (EndCaveBiome) biome.bclBiome, ceilPositions, random);
});
BiomePicker.ActualBiome biome = EndBiomes.getCaveBiome(pos.getX(), pos.getZ());
placeWalls(world, (EndCaveBiome) biome.bclBiome, caveBlocks, random);
fixBlocks(world, caveBlocks);
return true;
}
@Override
protected Set<BlockPos> generate(WorldGenLevel world, BlockPos center, int radius, RandomSource random) {
return null;
}
@Override
protected void placeFloor(WorldGenLevel world,
EndCaveBiome biome,
Set<BlockPos> floorPositions,
RandomSource random,
BlockState surfaceBlock) {
float density = biome.getFloorDensity() * 0.2F;
floorPositions.forEach((pos) -> {
if (!surfaceBlock.is(Blocks.END_STONE)) {
BlocksHelper.setWithoutUpdate(world, pos, surfaceBlock);
}
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getFloorFeature(random);
if (feature != null) {
feature.place(new FeaturePlaceContext<>(Optional.empty(), world, null, random, pos.above(), null));
}
}
});
}
@Override
protected void placeCeil(WorldGenLevel world,
EndCaveBiome biome,
Set<BlockPos> ceilPositions,
RandomSource random) {
float density = biome.getCeilDensity() * 0.2F;
ceilPositions.forEach((pos) -> {
BlockState ceilBlock = biome.getCeil(pos);
if (ceilBlock != null) {
BlocksHelper.setWithoutUpdate(world, pos, ceilBlock);
}
if (density > 0 && random.nextFloat() <= density) {
Feature<?> feature = biome.getCeilFeature(random);
if (feature != null) {
feature.place(new FeaturePlaceContext<>(Optional.empty(), world, null, random, pos.below(), null));
}
}
});
}
protected boolean hasCaves(WorldGenLevel world, BlockPos pos) {
return hasCavesInBiome(world, pos.offset(-8, 0, -8)) && hasCavesInBiome(
world,
pos.offset(8, 0, -8)
) && hasCavesInBiome(world,
pos.offset(-8,
0,
8)) && hasCavesInBiome(
world,
pos.offset(8, 0, 8));
}
protected boolean hasCavesInBiome(WorldGenLevel world, BlockPos pos) {
Holder<Biome> biome = world.getBiome(pos);
BCLBiome endBiome = BiomeAPI.getFromBiome(biome);
return endBiome.getCustomData("has_caves", true);
}
}

View file

@ -0,0 +1,256 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
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.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.*;
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.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class DragonTreeFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final Function<BlockState, Boolean> IGNORE;
private static final Function<PosInfo, BlockState> POST;
private static final List<Vector3f> BRANCH;
private static final List<Vector3f> SIDE1;
private static final List<Vector3f> SIDE2;
private static final List<Vector3f> ROOT;
@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(BlockTags.NYLIUM)) return false;
float size = MHelper.randRange(10, 25, random);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, size, 0, 6);
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
if (!SplineHelper.canGenerate(spline, pos, world, REPLACE)) {
return false;
}
BlocksHelper.setWithoutUpdate(world, pos, AIR);
Vector3f last = SplineHelper.getPos(spline, 3.5F);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
float radius = size * MHelper.randRange(0.5F, 0.7F, random);
makeCap(world, pos.offset(last.x(), last.y(), last.z()), radius, random, noise);
last = spline.get(0);
makeRoots(world, pos.offset(last.x(), last.y(), last.z()), radius, random);
radius = MHelper.randRange(1.2F, 2.3F, random);
SDF function = SplineHelper.buildSDF(spline, radius, 1.2F, (bpos) -> {
return EndBlocks.DRAGON_TREE.getBark().defaultBlockState();
});
function.setReplaceFunction(REPLACE);
function.addPostProcess(POST);
function.fillRecursiveIgnore(world, pos, IGNORE);
return true;
}
private void makeCap(WorldGenLevel world, BlockPos pos, float radius, RandomSource random, OpenSimplexNoise noise) {
int count = (int) radius;
int offset = (int) (BRANCH.get(BRANCH.size() - 1).y() * radius);
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(BRANCH);
SplineHelper.rotateSpline(branch, angle);
SplineHelper.scale(branch, scale);
SplineHelper.fillSpline(branch, world, EndBlocks.DRAGON_TREE.getBark().defaultBlockState(), pos, REPLACE);
branch = SplineHelper.copySpline(SIDE1);
SplineHelper.rotateSpline(branch, angle);
SplineHelper.scale(branch, scale);
SplineHelper.fillSpline(branch, world, EndBlocks.DRAGON_TREE.getBark().defaultBlockState(), pos, REPLACE);
branch = SplineHelper.copySpline(SIDE2);
SplineHelper.rotateSpline(branch, angle);
SplineHelper.scale(branch, scale);
SplineHelper.fillSpline(branch, world, EndBlocks.DRAGON_TREE.getBark().defaultBlockState(), pos, REPLACE);
}
leavesBall(world, pos.above(offset), radius * 1.15F + 2, random, noise);
}
private void makeRoots(WorldGenLevel world, BlockPos pos, float radius, RandomSource random) {
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,
EndBlocks.DRAGON_TREE.getBark().defaultBlockState(),
pos,
REPLACE);
}
}
}
private void leavesBall(WorldGenLevel world,
BlockPos pos,
float radius,
RandomSource random,
OpenSimplexNoise noise) {
SDF sphere = new SDFSphere().setRadius(radius)
.setBlock(EndBlocks.DRAGON_TREE_LEAVES.defaultBlockState()
.setValue(LeavesBlock.DISTANCE, 6));
SDF sub = new SDFScale().setScale(5).setSource(sphere);
sub = new SDFTranslate().setTranslate(0, -radius * 5, 0).setSource(sub);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub);
sphere = new SDFScale3D().setScale(1, 0.5F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 1.5F;
}).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return random.nextFloat() * 3F - 1.5F;
}).setSource(sphere);
MutableBlockPos mut = new MutableBlockPos();
sphere.addPostProcess((info) -> {
if (random.nextInt(5) == 0) {
for (Direction dir : Direction.values()) {
BlockState state = info.getState(dir, 2);
if (state.isAir()) {
return info.getState();
}
}
info.setState(EndBlocks.DRAGON_TREE.getBark().defaultBlockState());
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();
});
sphere.fillRecursiveIgnore(world, pos, IGNORE);
if (radius > 5) {
int count = (int) (radius * 2.5F);
for (int i = 0; i < count; i++) {
BlockPos p = pos.offset(
random.nextGaussian() * 1,
random.nextGaussian() * 1,
random.nextGaussian() * 1
);
boolean place = true;
for (Direction d : Direction.values()) {
BlockState state = world.getBlockState(p.relative(d));
if (!EndBlocks.DRAGON_TREE.isTreeLog(state) && !state.is(EndBlocks.DRAGON_TREE_LEAVES)) {
place = false;
break;
}
}
if (place) {
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.DRAGON_TREE.getBark());
}
}
}
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.DRAGON_TREE.getBark());
}
static {
REPLACE = (state) -> {
/*if (state.is(CommonBlockTags.END_STONES)) {
return true;
}*/
if (state.getBlock() == EndBlocks.DRAGON_TREE_LEAVES) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = (state) -> {
return EndBlocks.DRAGON_TREE.isTreeLog(state);
};
POST = (info) -> {
if (EndBlocks.DRAGON_TREE.isTreeLog(info.getStateUp()) && EndBlocks.DRAGON_TREE.isTreeLog(info.getStateDown())) {
return EndBlocks.DRAGON_TREE.getLog().defaultBlockState();
}
return info.getState();
};
BRANCH = Lists.newArrayList(
new Vector3f(0, 0, 0),
new Vector3f(0.1F, 0.3F, 0),
new Vector3f(0.4F, 0.6F, 0),
new Vector3f(0.8F, 0.8F, 0),
new Vector3f(1, 1, 0)
);
SIDE1 = Lists.newArrayList(new Vector3f(0.4F, 0.6F, 0), new Vector3f(0.8F, 0.8F, 0), new Vector3f(1, 1, 0));
SIDE2 = SplineHelper.copySpline(SIDE1);
Vector3f offset1 = new Vector3f(-0.4F, -0.6F, 0);
Vector3f offset2 = new Vector3f(0.4F, 0.6F, 0);
SplineHelper.offset(SIDE1, offset1);
SplineHelper.offset(SIDE2, offset1);
SplineHelper.rotateSpline(SIDE1, 0.5F);
SplineHelper.rotateSpline(SIDE2, -0.5F);
SplineHelper.offset(SIDE1, offset2);
SplineHelper.offset(SIDE2, offset2);
ROOT = Lists.newArrayList(
new Vector3f(0F, 1F, 0),
new Vector3f(0.1F, 0.7F, 0),
new Vector3f(0.3F, 0.3F, 0),
new Vector3f(0.7F, 0.05F, 0),
new Vector3f(0.8F, -0.2F, 0)
);
SplineHelper.offset(ROOT, new Vector3f(0, -0.45F, 0));
}
}

View file

@ -0,0 +1,379 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.Direction.AxisDirection;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
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.mojang.math.Vector3f;
import org.betterx.bclib.blocks.BaseAttachedBlock;
import org.betterx.bclib.sdf.PosInfo;
import org.betterx.bclib.sdf.SDF;
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.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class GiganticAmaranitaFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final Function<BlockState, Boolean> IGNORE;
private static final Function<PosInfo, BlockState> POST;
@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(BlockTags.NYLIUM)) return false;
float size = MHelper.randRange(5, 10, random);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, size, 0, 5);
SplineHelper.offsetParts(spline, random, 0.7F, 0, 0.7F);
if (!SplineHelper.canGenerate(spline, pos, world, REPLACE)) {
return false;
}
BlocksHelper.setWithoutUpdate(world, pos, AIR);
float radius = size * 0.17F;// MHelper.randRange(0.8F, 1.2F, random);
SDF function = SplineHelper.buildSDF(
spline,
radius,
0.2F,
(bpos) -> EndBlocks.AMARANITA_STEM.defaultBlockState()
);
Vector3f capPos = spline.get(spline.size() - 1);
makeHead(world, pos.offset(capPos.x() + 0.5F, capPos.y() + 1.5F, capPos.z() + 0.5F), Mth.floor(size / 1.6F));
function.setReplaceFunction(REPLACE);
function.addPostProcess(POST);
function.fillRecursiveIgnore(world, pos, IGNORE);
for (int i = 0; i < 3; i++) {
List<Vector3f> copy = SplineHelper.copySpline(spline);
SplineHelper.offsetParts(copy, random, 0.2F, 0, 0.2F);
SplineHelper.fillSplineForce(copy, world, EndBlocks.AMARANITA_HYPHAE.defaultBlockState(), pos, REPLACE);
}
return true;
}
private void makeHead(WorldGenLevel world, BlockPos pos, int radius) {
MutableBlockPos mut = new MutableBlockPos();
if (radius < 2) {
for (int i = -1; i < 2; i++) {
mut.set(pos).move(Direction.NORTH, 2).move(Direction.EAST, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.SOUTH, 2).move(Direction.EAST, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.EAST, 2).move(Direction.NORTH, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.WEST, 2).move(Direction.NORTH, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
}
for (int x = -1; x < 2; x++) {
for (int z = -1; z < 2; z++) {
mut.set(pos).move(x, 0, z);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN);
mut.move(Direction.DOWN);
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN);
mut.move(Direction.DOWN);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(
world,
mut,
EndBlocks.AMARANITA_FUR.defaultBlockState()
.setValue(BaseAttachedBlock.FACING, Direction.DOWN)
);
}
}
}
}
int h = radius + 1;
for (int y = 0; y < h; y++) {
mut.setY(pos.getY() + y + 1);
for (int x = -1; x < 2; x++) {
mut.setX(pos.getX() + x);
for (int z = -1; z < 2; z++) {
mut.setZ(pos.getZ() + z);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
}
}
}
mut.setY(pos.getY() + h + 1);
for (int x = -1; x < 2; x++) {
mut.setX(pos.getX() + x);
for (int z = -1; z < 2; z++) {
mut.setZ(pos.getZ() + z);
if ((x == 0 || z == 0) && world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
}
}
} else if (radius < 4) {
pos = pos.offset(-1, 0, -1);
for (int i = -2; i < 2; i++) {
mut.set(pos).move(Direction.NORTH, 2).move(Direction.WEST, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.SOUTH, 3).move(Direction.WEST, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.EAST, 3).move(Direction.NORTH, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.WEST, 2).move(Direction.NORTH, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
}
for (int x = -1; x < 3; x++) {
for (int z = -1; z < 3; z++) {
mut.set(pos).move(x, 0, z);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN);
mut.move(Direction.DOWN);
if ((x >> 1) == 0 || (z >> 1) == 0) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN);
Axis axis = x < 0 || x > 1 ? Axis.X : Axis.Z;
int distance = axis == Axis.X ? x < 0 ? -1 : 1 : z < 0 ? -1 : 1;
BlockPos offseted = mut.relative(axis, distance);
if (world.getBlockState(offseted).getMaterial().isReplaceable()) {
Direction dir = Direction.fromAxisAndDirection(
axis,
distance < 0 ? AxisDirection.NEGATIVE : AxisDirection.POSITIVE
);
BlocksHelper.setWithoutUpdate(
world,
offseted,
EndBlocks.AMARANITA_FUR.defaultBlockState()
.setValue(BaseAttachedBlock.FACING, dir)
);
}
mut.move(Direction.DOWN);
}
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(
world,
mut,
EndBlocks.AMARANITA_FUR.defaultBlockState()
.setValue(BaseAttachedBlock.FACING, Direction.DOWN)
);
}
}
}
}
int h = radius - 1;
for (int y = 0; y < h; y++) {
mut.setY(pos.getY() + y + 1);
for (int x = -1; x < 3; x++) {
mut.setX(pos.getX() + x);
for (int z = -1; z < 3; z++) {
mut.setZ(pos.getZ() + z);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
}
}
}
mut.setY(pos.getY() + h + 1);
for (int x = -1; x < 3; x++) {
mut.setX(pos.getX() + x);
for (int z = -1; z < 3; z++) {
mut.setZ(pos.getZ() + z);
if (((x >> 1) == 0 || (z >> 1) == 0) && world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
}
}
} else {
for (int i = -2; i < 3; i++) {
mut.set(pos).move(Direction.NORTH, 3).move(Direction.EAST, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.UP);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.NORTH);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.SOUTH, 3).move(Direction.EAST, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.UP);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.SOUTH);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.EAST, 3).move(Direction.NORTH, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.UP);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.EAST);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.set(pos).move(Direction.WEST, 3).move(Direction.NORTH, i);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.UP);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
mut.move(Direction.WEST);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
}
for (int i = 0; i < 4; i++) {
mut.set(pos)
.move(Direction.UP)
.move(BlocksHelper.HORIZONTAL[i], 3)
.move(BlocksHelper.HORIZONTAL[(i + 1) & 3], 3);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_HYMENOPHORE);
}
}
for (int x = -2; x < 3; x++) {
for (int z = -2; z < 3; z++) {
mut.set(pos).move(x, 0, z);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN);
mut.move(Direction.DOWN);
if ((x / 2) == 0 || (z / 2) == 0) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_LANTERN);
Axis axis = x < 0 || x > 1 ? Axis.X : Axis.Z;
int distance = axis == Axis.X ? x < 0 ? -1 : 1 : z < 0 ? -1 : 1;
BlockPos offseted = mut.relative(axis, distance);
if (world.getBlockState(offseted).getMaterial().isReplaceable()) {
Direction dir = Direction.fromAxisAndDirection(
axis,
distance < 0 ? AxisDirection.NEGATIVE : AxisDirection.POSITIVE
);
BlocksHelper.setWithoutUpdate(
world,
offseted,
EndBlocks.AMARANITA_FUR.defaultBlockState()
.setValue(BaseAttachedBlock.FACING, dir)
);
}
mut.move(Direction.DOWN);
}
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(
world,
mut,
EndBlocks.AMARANITA_FUR.defaultBlockState()
.setValue(BaseAttachedBlock.FACING, Direction.DOWN)
);
}
}
}
}
for (int y = 0; y < 3; y++) {
mut.setY(pos.getY() + y + 1);
for (int x = -2; x < 3; x++) {
mut.setX(pos.getX() + x);
for (int z = -2; z < 3; z++) {
mut.setZ(pos.getZ() + z);
if (world.getBlockState(mut).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
}
}
}
int h = radius + 1;
for (int y = 4; y < h; y++) {
mut.setY(pos.getY() + y);
for (int x = -2; x < 3; x++) {
mut.setX(pos.getX() + x);
for (int z = -2; z < 3; z++) {
mut.setZ(pos.getZ() + z);
if (y < 6) {
if (((x / 2) == 0 || (z / 2) == 0) && world.getBlockState(mut)
.getMaterial()
.isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
} else {
if ((x == 0 || z == 0) && (Math.abs(x) < 2 && Math.abs(z) < 2) && world.getBlockState(mut)
.getMaterial()
.isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, mut, EndBlocks.AMARANITA_CAP);
}
}
}
}
}
}
}
static {
REPLACE = (state) -> {
if (/*state.is(CommonBlockTags.END_STONES) || */state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = EndBlocks.DRAGON_TREE::isTreeLog;
POST = (info) -> {
if (!info.getStateUp().is(EndBlocks.AMARANITA_STEM) || !info.getStateDown().is(EndBlocks.AMARANITA_STEM)) {
return EndBlocks.AMARANITA_HYPHAE.defaultBlockState();
}
return info.getState();
};
}
}

View file

@ -0,0 +1,206 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
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.phys.AABB;
import com.mojang.math.Vector3f;
import org.betterx.bclib.sdf.PosInfo;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.*;
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.blocks.HelixTreeLeavesBlock;
import org.betterx.betterend.registry.EndBlocks;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public class HelixTreeFeature extends DefaultFeature {
private static final Function<PosInfo, BlockState> POST;
@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(BlockTags.NYLIUM)) return false;
BlocksHelper.setWithoutUpdate(world, pos, AIR);
float angle = random.nextFloat() * MHelper.PI2;
float radiusRange = MHelper.randRange(4.5F, 6F, random);
float scale = MHelper.randRange(0.5F, 1F, random);
float dx;
float dz;
List<Vector3f> spline = new ArrayList<Vector3f>(10);
for (int i = 0; i < 10; i++) {
float radius = (0.9F - i * 0.1F) * radiusRange;
dx = (float) Math.sin(i + angle) * radius;
dz = (float) Math.cos(i + angle) * radius;
spline.add(new Vector3f(dx, i * 2, dz));
}
SDF sdf = SplineHelper.buildSDF(spline, 1.7F, 0.5F, (p) -> {
return EndBlocks.HELIX_TREE.getBark().defaultBlockState();
});
SDF rotated = new SDFRotation().setRotation(Vector3f.YP, (float) Math.PI).setSource(sdf);
sdf = new SDFUnion().setSourceA(rotated).setSourceB(sdf);
Vector3f lastPoint = spline.get(spline.size() - 1);
List<Vector3f> spline2 = SplineHelper.makeSpline(0, 0, 0, 0, 20, 0, 5);
SDF stem = SplineHelper.buildSDF(spline2, 1.0F, 0.5F, (p) -> {
return EndBlocks.HELIX_TREE.getBark().defaultBlockState();
});
stem = new SDFTranslate().setTranslate(lastPoint.x(), lastPoint.y(), lastPoint.z()).setSource(stem);
sdf = new SDFSmoothUnion().setRadius(3).setSourceA(sdf).setSourceB(stem);
sdf = new SDFScale().setScale(scale).setSource(sdf);
dx = 30 * scale;
float dy1 = -20 * scale;
float dy2 = 100 * scale;
sdf.addPostProcess(POST).fillArea(world, pos, new AABB(pos.offset(-dx, dy1, -dx), pos.offset(dx, dy2, dx)));
SplineHelper.scale(spline, scale);
SplineHelper.fillSplineForce(spline,
world,
EndBlocks.HELIX_TREE.getBark().defaultBlockState(),
pos,
(state) -> {
return state.getMaterial().isReplaceable();
});
SplineHelper.rotateSpline(spline, (float) Math.PI);
SplineHelper.fillSplineForce(spline,
world,
EndBlocks.HELIX_TREE.getBark().defaultBlockState(),
pos,
(state) -> {
return state.getMaterial().isReplaceable();
});
SplineHelper.scale(spline2, scale);
BlockPos leafStart = pos.offset(lastPoint.x() + 0.5, lastPoint.y() + 0.5, lastPoint.z() + 0.5);
SplineHelper.fillSplineForce(
spline2,
world,
EndBlocks.HELIX_TREE.getLog().defaultBlockState(),
leafStart,
(state) -> {
return state.getMaterial().isReplaceable();
}
);
spline.clear();
float rad = MHelper.randRange(8F, 11F, random);
int count = MHelper.randRange(20, 30, random);
float scaleM = 20F / (float) count * scale * 1.75F;
float hscale = 20F / (float) count * 0.05F;
for (int i = 0; i <= count; i++) {
float radius = 1 - i * hscale;
radius = radius * radius * 2 - 1;
radius *= radius;
radius = (1 - radius) * rad * scale;
dx = (float) Math.sin(i * 0.45F + angle) * radius;
dz = (float) Math.cos(i * 0.45F + angle) * radius;
spline.add(new Vector3f(dx, i * scaleM, dz));
}
Vector3f start = new Vector3f();
Vector3f end = new Vector3f();
lastPoint = spline.get(0);
BlockState leaf = EndBlocks.HELIX_TREE_LEAVES.defaultBlockState();
for (int i = 1; i < spline.size(); i++) {
Vector3f point = spline.get(i);
int minY = MHelper.floor(lastPoint.y());
int maxY = MHelper.floor(point.y());
float div = point.y() - lastPoint.y();
for (float py = minY; py <= maxY; py += 0.2F) {
start.set(0, py, 0);
float delta = (py - minY) / div;
float px = Mth.lerp(delta, lastPoint.x(), point.x());
float pz = Mth.lerp(delta, lastPoint.z(), point.z());
end.set(px, py, pz);
fillLine(start, end, world, leaf, leafStart, i / 2 - 1);
float ax = Math.abs(px);
float az = Math.abs(pz);
if (ax > az) {
start.set(start.x(), start.y(), start.z() + az > 0 ? 1 : -1);
end.set(end.x(), end.y(), end.z() + az > 0 ? 1 : -1);
} else {
start.set(start.x() + ax > 0 ? 1 : -1, start.y(), start.z());
end.set(end.x() + ax > 0 ? 1 : -1, end.y(), end.z());
}
fillLine(start, end, world, leaf, leafStart, i / 2 - 1);
}
lastPoint = point;
}
leaf = leaf.setValue(HelixTreeLeavesBlock.COLOR, 7);
leafStart = leafStart.offset(0, lastPoint.y(), 0);
if (world.getBlockState(leafStart).isAir()) {
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
leafStart = leafStart.above();
if (world.getBlockState(leafStart).isAir()) {
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
leafStart = leafStart.above();
if (world.getBlockState(leafStart).isAir()) {
BlocksHelper.setWithoutUpdate(world, leafStart, leaf);
}
}
}
return true;
}
private void fillLine(Vector3f start,
Vector3f end,
WorldGenLevel world,
BlockState state,
BlockPos pos,
int offset) {
float dx = end.x() - start.x();
float dy = end.y() - start.y();
float dz = end.z() - start.z();
float max = MHelper.max(Math.abs(dx), Math.abs(dy), Math.abs(dz));
int count = MHelper.floor(max + 1);
dx /= max;
dy /= max;
dz /= max;
float x = start.x();
float y = start.y();
float z = start.z();
MutableBlockPos bPos = new MutableBlockPos();
for (int i = 0; i < count; i++) {
bPos.set(x + pos.getX(), y + pos.getY(), z + pos.getZ());
int color = MHelper.floor((float) i / (float) count * 7F + 0.5F) + offset;
color = Mth.clamp(color, 0, 7);
if (world.getBlockState(bPos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, bPos, state.setValue(HelixTreeLeavesBlock.COLOR, color));
}
x += dx;
y += dy;
z += dz;
}
bPos.set(end.x() + pos.getX(), end.y() + pos.getY(), end.z() + pos.getZ());
if (world.getBlockState(bPos).getMaterial().isReplaceable()) {
BlocksHelper.setWithoutUpdate(world, bPos, state.setValue(HelixTreeLeavesBlock.COLOR, 7));
}
}
static {
POST = (info) -> {
if (EndBlocks.HELIX_TREE.isTreeLog(info.getStateUp()) && EndBlocks.HELIX_TREE.isTreeLog(info.getStateDown())) {
return EndBlocks.HELIX_TREE.getLog().defaultBlockState();
}
return info.getState();
};
}
}

View file

@ -0,0 +1,128 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
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.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.*;
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.blocks.JellyshroomCapBlock;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class JellyshroomFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final List<Vector3f> ROOT;
@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(BlockTags.NYLIUM)) return false;
BlockState bark = EndBlocks.JELLYSHROOM.getBark().defaultBlockState();
BlockState membrane = EndBlocks.JELLYSHROOM_CAP_PURPLE.defaultBlockState();
int height = MHelper.randRange(5, 8, random);
float radius = height * MHelper.randRange(0.15F, 0.25F, random);
List<Vector3f> spline = SplineHelper.makeSpline(0, -1, 0, 0, height, 0, 3);
SplineHelper.offsetParts(spline, random, 0.5F, 0, 0.5F);
SDF sdf = SplineHelper.buildSDF(spline, radius, 0.8F, (bpos) -> {
return bark;
});
radius = height * MHelper.randRange(0.7F, 0.9F, random);
if (radius < 1.5F) {
radius = 1.5F;
}
final float membraneRadius = radius;
SDF cap = makeCap(membraneRadius, random, membrane);
final Vector3f last = spline.get(spline.size() - 1);
cap = new SDFTranslate().setTranslate(last.x(), last.y(), last.z()).setSource(cap);
sdf = new SDFSmoothUnion().setRadius(3F).setSourceA(sdf).setSourceB(cap);
sdf.setReplaceFunction(REPLACE).addPostProcess((info) -> {
if (EndBlocks.JELLYSHROOM.isTreeLog(info.getState())) {
if (EndBlocks.JELLYSHROOM.isTreeLog(info.getStateUp()) && EndBlocks.JELLYSHROOM.isTreeLog(info.getStateDown())) {
return EndBlocks.JELLYSHROOM.getLog().defaultBlockState();
}
} else if (info.getState().is(EndBlocks.JELLYSHROOM_CAP_PURPLE)) {
float dx = info.getPos().getX() - pos.getX() - last.x();
float dz = info.getPos().getZ() - pos.getZ() - last.z();
float distance = MHelper.length(dx, dz) / membraneRadius * 7F;
int color = Mth.clamp(MHelper.floor(distance), 0, 7);
return info.getState().setValue(JellyshroomCapBlock.COLOR, color);
}
return info.getState();
}).fillRecursive(world, pos);
radius = height * 0.5F;
makeRoots(world, pos.offset(0, 2, 0), radius, random, bark);
return true;
}
private void makeRoots(WorldGenLevel world, BlockPos pos, float radius, RandomSource random, BlockState wood) {
int count = (int) (radius * 3.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, REPLACE);
}
}
}
private SDF makeCap(float radius, RandomSource random, BlockState cap) {
SDF sphere = new SDFSphere().setRadius(radius).setBlock(cap);
SDF sub = new SDFTranslate().setTranslate(0, -4, 0).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub);
sphere = new SDFScale3D().setScale(1, 0.5F, 1).setSource(sphere);
sphere = new SDFTranslate().setTranslate(0, 1 - radius * 0.5F, 0).setSource(sphere);
float angle = random.nextFloat() * MHelper.PI2;
int count = (int) MHelper.randRange(radius * 0.5F, radius, random);
if (count < 3) {
count = 3;
}
sphere = new SDFFlatWave().setAngle(angle).setRaysCount(count).setIntensity(0.2F).setSource(sphere);
return sphere;
}
static {
ROOT = Lists.newArrayList(
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));
REPLACE = (state) -> {
if (/*state.is(CommonBlockTags.END_STONES) || */state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,223 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
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.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.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
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.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class LacugroveFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final Function<BlockState, Boolean> IGNORE;
private static final Function<PosInfo, BlockState> POST;
@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(BlockTags.NYLIUM)) return false;
float size = MHelper.randRange(15, 25, random);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, size, 0, 6);
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
if (!SplineHelper.canGenerate(spline, pos, world, REPLACE)) {
return false;
}
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
float radius = MHelper.randRange(6F, 8F, random);
radius *= (size - 15F) / 20F + 1F;
Vector3f center = spline.get(4);
leavesBall(world, pos.offset(center.x(), center.y(), center.z()), radius, random, noise);
radius = MHelper.randRange(1.2F, 1.8F, random);
SDF function = SplineHelper.buildSDF(spline, radius, 0.7F, (bpos) -> {
return EndBlocks.LACUGROVE.getBark().defaultBlockState();
});
function.setReplaceFunction(REPLACE);
function.addPostProcess(POST);
function.fillRecursive(world, pos);
spline = spline.subList(4, 6);
SplineHelper.fillSpline(spline, world, EndBlocks.LACUGROVE.getBark().defaultBlockState(), pos, REPLACE);
MutableBlockPos mut = new MutableBlockPos();
int offset = random.nextInt(2);
for (int i = 0; i < 100; i++) {
double px = pos.getX() + MHelper.randRange(-5, 5, random);
double pz = pos.getZ() + MHelper.randRange(-5, 5, random);
mut.setX(MHelper.floor(px + 0.5));
mut.setZ(MHelper.floor(pz + 0.5));
if (((mut.getX() + mut.getZ() + offset) & 1) == 0) {
double distance = 3.5 - MHelper.length(px - pos.getX(), pz - pos.getZ()) * 0.5;
if (distance > 0) {
int minY = MHelper.floor(pos.getY() - distance * 0.5);
int maxY = MHelper.floor(pos.getY() + distance + random.nextDouble());
boolean generate = false;
for (int y = minY; y < maxY; y++) {
mut.setY(y);
if (world.getBlockState(mut).is(CommonBlockTags.END_STONES)) {
generate = true;
break;
}
}
if (generate) {
int top = maxY - 1;
for (int y = top; y >= minY; y--) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (state.getMaterial().isReplaceable() || state.getMaterial()
.equals(Material.PLANT) || state.is(
CommonBlockTags.END_STONES)) {
BlocksHelper.setWithoutUpdate(
world,
mut,
y == top ? EndBlocks.LACUGROVE.getBark() : EndBlocks.LACUGROVE.getLog()
);
} else {
break;
}
}
}
}
}
}
return true;
}
private void leavesBall(WorldGenLevel world,
BlockPos pos,
float radius,
RandomSource random,
OpenSimplexNoise noise) {
SDF sphere = new SDFSphere().setRadius(radius)
.setBlock(EndBlocks.LACUGROVE_LEAVES.defaultBlockState()
.setValue(LeavesBlock.DISTANCE, 6));
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 3;
}).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return random.nextFloat() * 3F - 1.5F;
}).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere)
.setSourceB(new SDFTranslate().setTranslate(0, -radius - 2, 0).setSource(sphere));
MutableBlockPos mut = new MutableBlockPos();
sphere.addPostProcess((info) -> {
if (random.nextInt(5) == 0) {
for (Direction dir : Direction.values()) {
BlockState state = info.getState(dir, 2);
if (state.isAir()) {
return info.getState();
}
}
info.setState(EndBlocks.LACUGROVE.getBark().defaultBlockState());
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();
});
sphere.fillRecursiveIgnore(world, pos, IGNORE);
if (radius > 5) {
int count = (int) (radius * 2.5F);
for (int i = 0; i < count; i++) {
BlockPos p = pos.offset(
random.nextGaussian() * 1,
random.nextGaussian() * 1,
random.nextGaussian() * 1
);
boolean place = true;
for (Direction d : Direction.values()) {
BlockState state = world.getBlockState(p.relative(d));
if (!EndBlocks.LACUGROVE.isTreeLog(state) && !state.is(EndBlocks.LACUGROVE_LEAVES)) {
place = false;
break;
}
}
if (place) {
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.LACUGROVE.getBark());
}
}
}
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.LACUGROVE.getBark());
}
static {
REPLACE = (state) -> {
/*if (state.is(CommonBlockTags.END_STONES)) {
return true;
}*/
if (EndBlocks.LACUGROVE.isTreeLog(state)) {
return true;
}
if (state.getBlock() == EndBlocks.LACUGROVE_LEAVES) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = (state) -> {
return EndBlocks.LACUGROVE.isTreeLog(state);
};
POST = (info) -> {
if (EndBlocks.LACUGROVE.isTreeLog(info.getStateUp()) && EndBlocks.LACUGROVE.isTreeLog(info.getStateDown())) {
return EndBlocks.LACUGROVE.getLog().defaultBlockState();
}
return info.getState();
};
}
}

View file

@ -0,0 +1,234 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
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.collect.Lists;
import com.mojang.math.Vector3f;
import org.betterx.bclib.api.tag.CommonBlockTags;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.*;
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.blocks.basis.FurBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class LucerniaFeature extends DefaultFeature {
private static final Direction[] DIRECTIONS = Direction.values();
private static final Function<BlockState, Boolean> REPLACE;
private static final Function<BlockState, Boolean> IGNORE;
private static final List<Vector3f> SPLINE;
private static final List<Vector3f> ROOT;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
final NoneFeatureConfiguration config = featureConfig.config();
if (!world.getBlockState(pos.below()).is(BlockTags.NYLIUM)) return false;
float size = MHelper.randRange(12, 20, random);
int count = (int) (size * 0.3F);
float var = MHelper.PI2 / (float) (count * 3);
float start = MHelper.randRange(0, MHelper.PI2, random);
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);
SplineHelper.rotateSpline(spline, angle);
SplineHelper.scale(spline, size * MHelper.randRange(0.5F, 1F, random));
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
SplineHelper.fillSpline(spline, world, EndBlocks.LUCERNIA.getBark().defaultBlockState(), pos, REPLACE);
Vector3f last = spline.get(spline.size() - 1);
float leavesRadius = (size * 0.13F + MHelper.randRange(0.8F, 1.5F, random)) * 1.4F;
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
leavesBall(world, pos.offset(last.x(), last.y(), last.z()), leavesRadius, random, noise, config != null);
}
makeRoots(world, pos.offset(0, MHelper.randRange(3, 5, random), 0), size * 0.35F, random);
return true;
}
private void leavesBall(WorldGenLevel world,
BlockPos pos,
float radius,
RandomSource random,
OpenSimplexNoise noise,
boolean natural) {
SDF sphere = new SDFSphere().setRadius(radius)
.setBlock(EndBlocks.LUCERNIA_LEAVES.defaultBlockState()
.setValue(LeavesBlock.DISTANCE, 6));
SDF sub = new SDFScale().setScale(5).setSource(sphere);
sub = new SDFTranslate().setTranslate(0, -radius * 5, 0).setSource(sub);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub);
sphere = new SDFScale3D().setScale(1, 0.75F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> (float) noise.eval(
vec.x() * 0.2,
vec.y() * 0.2,
vec.z() * 0.2
) * 2F).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> MHelper.randRange(-1.5F, 1.5F, random)).setSource(sphere);
MutableBlockPos mut = new MutableBlockPos();
for (Direction d1 : BlocksHelper.HORIZONTAL) {
BlockPos p = mut.set(pos).move(Direction.UP).move(d1).immutable();
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.LUCERNIA.getBark().defaultBlockState());
for (Direction d2 : BlocksHelper.HORIZONTAL) {
mut.set(p).move(Direction.UP).move(d2);
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.LUCERNIA.getBark().defaultBlockState());
}
}
BlockState top = EndBlocks.FILALUX.defaultBlockState().setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP);
BlockState middle = EndBlocks.FILALUX.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
BlockState bottom = EndBlocks.FILALUX.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
BlockState outer = EndBlocks.LUCERNIA_OUTER_LEAVES.defaultBlockState();
List<BlockPos> support = Lists.newArrayList();
sphere.addPostProcess((info) -> {
if (natural && random.nextInt(6) == 0 && info.getStateDown().isAir()) {
BlockPos d = info.getPos().below();
support.add(d);
}
if (random.nextInt(15) == 0) {
for (Direction dir : Direction.values()) {
BlockState state = info.getState(dir, 2);
if (state.isAir()) {
return info.getState();
}
}
info.setState(EndBlocks.LUCERNIA.getBark().defaultBlockState());
}
MHelper.shuffle(DIRECTIONS, random);
for (Direction d : DIRECTIONS) {
if (info.getState(d).isAir()) {
info.setBlockPos(info.getPos().relative(d), outer.setValue(FurBlock.FACING, d));
}
}
if (EndBlocks.LUCERNIA.isTreeLog(info.getState())) {
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();
});
sphere.fillRecursiveIgnore(world, pos, IGNORE);
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.LUCERNIA.getBark());
support.forEach((bpos) -> {
BlockState state = world.getBlockState(bpos);
if (state.isAir() || state.is(EndBlocks.LUCERNIA_OUTER_LEAVES)) {
int count = MHelper.randRange(3, 8, random);
mut.set(bpos);
if (world.getBlockState(mut.above()).is(EndBlocks.LUCERNIA_LEAVES)) {
BlocksHelper.setWithoutUpdate(world, mut, top);
for (int i = 1; i < count; i++) {
mut.setY(mut.getY() - 1);
if (world.isEmptyBlock(mut.below())) {
BlocksHelper.setWithoutUpdate(world, mut, middle);
} else {
break;
}
}
BlocksHelper.setWithoutUpdate(world, mut, bottom);
}
}
});
}
private void makeRoots(WorldGenLevel world, BlockPos pos, float radius, RandomSource random) {
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.fillSplineForce(branch,
world,
EndBlocks.LUCERNIA.getBark().defaultBlockState(),
pos,
REPLACE);
}
}
}
static {
REPLACE = (state) -> {
/*if (state.is(CommonBlockTags.END_STONES)) {
return true;
}*/
if (state.getBlock() == EndBlocks.LUCERNIA_LEAVES) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = EndBlocks.LUCERNIA::isTreeLog;
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(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));
}
}

View file

@ -0,0 +1,173 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
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.mojang.math.Vector3f;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.*;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.sdf.primitive.SDFPrimitive;
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.blocks.MossyGlowshroomCapBlock;
import org.betterx.betterend.blocks.basis.FurBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class MossyGlowshroomFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final Vector3f CENTER = new Vector3f();
private static final SDFBinary FUNCTION;
private static final SDFTranslate HEAD_POS;
private static final SDFFlatWave ROOTS_ROT;
private static final SDFPrimitive CONE1;
private static final SDFPrimitive CONE2;
private static final SDFPrimitive CONE_GLOW;
private static final SDFPrimitive ROOTS;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos blockPos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
BlockState down = world.getBlockState(blockPos.below());
if (!down.is(EndBlocks.END_MYCELIUM) && !down.is(EndBlocks.END_MOSS)) return false;
CONE1.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP);
CONE2.setBlock(EndBlocks.MOSSY_GLOWSHROOM_CAP);
CONE_GLOW.setBlock(EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE);
ROOTS.setBlock(EndBlocks.MOSSY_GLOWSHROOM.getBark());
float height = MHelper.randRange(10F, 25F, random);
int count = MHelper.floor(height / 4);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, height, 0, count);
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
SDF sdf = SplineHelper.buildSDF(spline, 2.1F, 1.5F, (pos) -> {
return EndBlocks.MOSSY_GLOWSHROOM.getLog().defaultBlockState();
});
Vector3f pos = spline.get(spline.size() - 1);
float scale = MHelper.randRange(0.75F, 1.1F, random);
if (!SplineHelper.canGenerate(spline, scale, blockPos, world, REPLACE)) {
return false;
}
BlocksHelper.setWithoutUpdate(world, blockPos, AIR);
CENTER.set(blockPos.getX(), 0, blockPos.getZ());
HEAD_POS.setTranslate(pos.x(), pos.y(), pos.z());
ROOTS_ROT.setAngle(random.nextFloat() * MHelper.PI2);
FUNCTION.setSourceA(sdf);
new SDFScale().setScale(scale).setSource(FUNCTION).setReplaceFunction(REPLACE).addPostProcess((info) -> {
if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getState())) {
if (random.nextBoolean() && info.getStateUp().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()
.setValue(MossyGlowshroomCapBlock.TRANSITION, true));
return info.getState();
} else if (!EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateUp()) || !EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(
info.getStateDown())) {
info.setState(EndBlocks.MOSSY_GLOWSHROOM.getBark().defaultBlockState());
return info.getState();
}
} else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_CAP) {
if (EndBlocks.MOSSY_GLOWSHROOM.isTreeLog(info.getStateDown().getBlock())) {
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState()
.setValue(MossyGlowshroomCapBlock.TRANSITION, true));
return info.getState();
}
info.setState(EndBlocks.MOSSY_GLOWSHROOM_CAP.defaultBlockState());
return info.getState();
} else if (info.getState().getBlock() == EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
for (Direction dir : BlocksHelper.HORIZONTAL) {
if (info.getState(dir) == AIR) {
info.setBlockPos(
info.getPos().relative(dir),
EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, dir)
);
}
}
if (info.getStateDown().getBlock() != EndBlocks.MOSSY_GLOWSHROOM_HYMENOPHORE) {
info.setBlockPos(
info.getPos().below(),
EndBlocks.MOSSY_GLOWSHROOM_FUR.defaultBlockState().setValue(FurBlock.FACING, Direction.DOWN)
);
}
}
return info.getState();
}).fillRecursive(world, blockPos);
return true;
}
static {
SDFCappedCone cone1 = new SDFCappedCone().setHeight(2.5F).setRadius1(1.5F).setRadius2(2.5F);
SDFCappedCone cone2 = new SDFCappedCone().setHeight(3F).setRadius1(2.5F).setRadius2(13F);
SDF posedCone2 = new SDFTranslate().setTranslate(0, 5, 0).setSource(cone2);
SDF posedCone3 = new SDFTranslate().setTranslate(0, 12F, 0)
.setSource(new SDFScale().setScale(2).setSource(cone2));
SDF upCone = new SDFSubtraction().setSourceA(posedCone2).setSourceB(posedCone3);
SDF wave = new SDFFlatWave().setRaysCount(12).setIntensity(1.3F).setSource(upCone);
SDF cones = new SDFSmoothUnion().setRadius(3).setSourceA(cone1).setSourceB(wave);
CONE1 = cone1;
CONE2 = cone2;
SDF innerCone = new SDFTranslate().setTranslate(0, 1.25F, 0).setSource(upCone);
innerCone = new SDFScale3D().setScale(1.2F, 1F, 1.2F).setSource(innerCone);
cones = new SDFUnion().setSourceA(cones).setSourceB(innerCone);
SDF glowCone = new SDFCappedCone().setHeight(3F).setRadius1(2F).setRadius2(12.5F);
CONE_GLOW = (SDFPrimitive) glowCone;
glowCone = new SDFTranslate().setTranslate(0, 4.25F, 0).setSource(glowCone);
glowCone = new SDFSubtraction().setSourceA(glowCone).setSourceB(posedCone3);
cones = new SDFUnion().setSourceA(cones).setSourceB(glowCone);
OpenSimplexNoise noise = new OpenSimplexNoise(1234);
cones = new SDFCoordModify().setFunction((pos) -> {
float dist = MHelper.length(pos.x(), pos.z());
float y = pos.y() + (float) noise.eval(
pos.x() * 0.1 + CENTER.x(),
pos.z() * 0.1 + CENTER.z()
) * dist * 0.3F - dist * 0.15F;
pos.set(pos.x(), y, pos.z());
}).setSource(cones);
HEAD_POS = (SDFTranslate) new SDFTranslate().setSource(new SDFTranslate().setTranslate(0, 2.5F, 0)
.setSource(cones));
SDF roots = new SDFSphere().setRadius(4F);
ROOTS = (SDFPrimitive) roots;
roots = new SDFScale3D().setScale(1, 0.7F, 1).setSource(roots);
ROOTS_ROT = (SDFFlatWave) new SDFFlatWave().setRaysCount(5).setIntensity(1.5F).setSource(roots);
FUNCTION = new SDFSmoothUnion().setRadius(4)
.setSourceB(new SDFUnion().setSourceA(HEAD_POS).setSourceB(ROOTS_ROT));
REPLACE = (state) -> {
/*if (state.is(CommonBlockTags.END_STONES)) {
return true;
}*/
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
}

View file

@ -0,0 +1,222 @@
package org.betterx.betterend.world.features.trees;
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.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.mojang.math.Vector3f;
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.SDFScale3D;
import org.betterx.bclib.sdf.operator.SDFSubtraction;
import org.betterx.bclib.sdf.operator.SDFTranslate;
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.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class PythadendronTreeFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final Function<BlockState, Boolean> IGNORE;
private static final Function<PosInfo, BlockState> POST;
@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()).getBlock() != EndBlocks.CHORUS_NYLIUM) {
return false;
}
BlocksHelper.setWithoutUpdate(world, pos, AIR);
float size = MHelper.randRange(10, 20, random);
List<Vector3f> spline = SplineHelper.makeSpline(0, 0, 0, 0, size, 0, 4);
SplineHelper.offsetParts(spline, random, 0.7F, 0, 0.7F);
Vector3f last = spline.get(spline.size() - 1);
int depth = MHelper.floor((size - 10F) * 3F / 10F + 1F);
float bsize = (10F - (size - 10F)) / 10F + 1.5F;
branch(
last.x(),
last.y(),
last.z(),
size * bsize,
MHelper.randRange(0, MHelper.PI2, random),
random,
depth,
world,
pos
);
SDF function = SplineHelper.buildSDF(spline, 1.7F, 1.1F, (bpos) -> {
return EndBlocks.PYTHADENDRON.getBark().defaultBlockState();
});
function.setReplaceFunction(REPLACE);
function.addPostProcess(POST);
function.fillRecursive(world, pos);
return true;
}
private void branch(float x,
float y,
float z,
float size,
float angle,
RandomSource random,
int depth,
WorldGenLevel world,
BlockPos pos) {
if (depth == 0) return;
float dx = (float) Math.cos(angle) * size * 0.15F;
float dz = (float) Math.sin(angle) * size * 0.15F;
float x1 = x + dx;
float z1 = z + dz;
float x2 = x - dx;
float z2 = z - dz;
List<Vector3f> spline = SplineHelper.makeSpline(x, y, z, x1, y, z1, 5);
SplineHelper.powerOffset(spline, size * MHelper.randRange(1.0F, 2.0F, random), 4);
SplineHelper.offsetParts(spline, random, 0.3F, 0, 0.3F);
Vector3f pos1 = spline.get(spline.size() - 1);
boolean s1 = SplineHelper.fillSpline(
spline,
world,
EndBlocks.PYTHADENDRON.getBark().defaultBlockState(),
pos,
REPLACE
);
spline = SplineHelper.makeSpline(x, y, z, x2, y, z2, 5);
SplineHelper.powerOffset(spline, size * MHelper.randRange(1.0F, 2.0F, random), 4);
SplineHelper.offsetParts(spline, random, 0.3F, 0, 0.3F);
Vector3f pos2 = spline.get(spline.size() - 1);
boolean s2 = SplineHelper.fillSpline(
spline,
world,
EndBlocks.PYTHADENDRON.getBark().defaultBlockState(),
pos,
REPLACE
);
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextInt());
if (depth < 3) {
if (s1) {
leavesBall(world, pos.offset(pos1.x(), pos1.y(), pos1.z()), random, noise);
}
if (s2) {
leavesBall(world, pos.offset(pos2.x(), pos2.y(), pos2.z()), random, noise);
}
}
float size1 = size * MHelper.randRange(0.75F, 0.95F, random);
float size2 = size * MHelper.randRange(0.75F, 0.95F, random);
float angle1 = angle + (float) Math.PI * 0.5F + MHelper.randRange(-0.1F, 0.1F, random);
float angle2 = angle + (float) Math.PI * 0.5F + MHelper.randRange(-0.1F, 0.1F, random);
if (s1) {
branch(pos1.x(), pos1.y(), pos1.z(), size1, angle1, random, depth - 1, world, pos);
}
if (s2) {
branch(pos2.x(), pos2.y(), pos2.z(), size2, angle2, random, depth - 1, world, pos);
}
}
private void leavesBall(WorldGenLevel world, BlockPos pos, RandomSource random, OpenSimplexNoise noise) {
float radius = MHelper.randRange(4.5F, 6.5F, random);
SDF sphere = new SDFSphere().setRadius(radius)
.setBlock(EndBlocks.PYTHADENDRON_LEAVES.defaultBlockState()
.setValue(LeavesBlock.DISTANCE, 6));
sphere = new SDFScale3D().setScale(1, 0.6F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return (float) noise.eval(vec.x() * 0.2, vec.y() * 0.2, vec.z() * 0.2) * 3;
}).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> {
return random.nextFloat() * 3F - 1.5F;
}).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere)
.setSourceB(new SDFTranslate().setTranslate(0, -radius, 0).setSource(sphere));
MutableBlockPos mut = new MutableBlockPos();
sphere.addPostProcess((info) -> {
if (random.nextInt(5) == 0) {
for (Direction dir : Direction.values()) {
BlockState state = info.getState(dir, 2);
if (state.isAir()) {
return info.getState();
}
}
info.setState(EndBlocks.PYTHADENDRON.getBark().defaultBlockState());
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();
});
sphere.fillRecursiveIgnore(world, pos, IGNORE);
}
static {
REPLACE = (state) -> {
/*if (state.is(CommonBlockTags.END_STONES)) {
return true;
}*/
if (state.getBlock() == EndBlocks.PYTHADENDRON_LEAVES) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = (state) -> {
return EndBlocks.PYTHADENDRON.isTreeLog(state);
};
POST = (info) -> {
if (EndBlocks.PYTHADENDRON.isTreeLog(info.getStateUp()) && EndBlocks.PYTHADENDRON.isTreeLog(info.getStateDown())) {
return EndBlocks.PYTHADENDRON.getLog().defaultBlockState();
}
return info.getState();
};
}
}

View file

@ -0,0 +1,201 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
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.collect.Lists;
import com.mojang.math.Vector3f;
import org.betterx.bclib.blocks.BlockProperties;
import org.betterx.bclib.blocks.BlockProperties.TripleShape;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.*;
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.blocks.basis.FurBlock;
import org.betterx.betterend.noise.OpenSimplexNoise;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class TenaneaFeature extends DefaultFeature {
private static final Direction[] DIRECTIONS = Direction.values();
private static final Function<BlockState, Boolean> REPLACE;
private static final Function<BlockState, Boolean> IGNORE;
private static final List<Vector3f> SPLINE;
@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(BlockTags.NYLIUM)) return false;
float size = MHelper.randRange(7, 10, random);
int count = (int) (size * 0.45F);
float var = MHelper.PI2 / (float) (count * 3);
float start = MHelper.randRange(0, MHelper.PI2, random);
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);
SplineHelper.rotateSpline(spline, angle);
SplineHelper.scale(spline, size + MHelper.randRange(0, size * 0.5F, random));
SplineHelper.offsetParts(spline, random, 1F, 0, 1F);
SplineHelper.fillSpline(spline, world, EndBlocks.TENANEA.getBark().defaultBlockState(), pos, REPLACE);
Vector3f last = spline.get(spline.size() - 1);
float leavesRadius = (size * 0.3F + MHelper.randRange(0.8F, 1.5F, random)) * 1.4F;
OpenSimplexNoise noise = new OpenSimplexNoise(random.nextLong());
leavesBall(world, pos.offset(last.x(), last.y(), last.z()), leavesRadius, random, noise);
}
return true;
}
private void leavesBall(WorldGenLevel world,
BlockPos pos,
float radius,
RandomSource random,
OpenSimplexNoise noise) {
SDF sphere = new SDFSphere().setRadius(radius)
.setBlock(EndBlocks.TENANEA_LEAVES.defaultBlockState()
.setValue(LeavesBlock.DISTANCE, 6));
SDF sub = new SDFScale().setScale(5).setSource(sphere);
sub = new SDFTranslate().setTranslate(0, -radius * 5, 0).setSource(sub);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub);
sphere = new SDFScale3D().setScale(1, 0.75F, 1).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> (float) noise.eval(
vec.x() * 0.2,
vec.y() * 0.2,
vec.z() * 0.2
) * 2F).setSource(sphere);
sphere = new SDFDisplacement().setFunction((vec) -> MHelper.randRange(-1.5F, 1.5F, random)).setSource(sphere);
MutableBlockPos mut = new MutableBlockPos();
for (Direction d1 : BlocksHelper.HORIZONTAL) {
BlockPos p = mut.set(pos).move(Direction.UP).move(d1).immutable();
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TENANEA.getBark().defaultBlockState());
for (Direction d2 : BlocksHelper.HORIZONTAL) {
mut.set(p).move(Direction.UP).move(d2);
BlocksHelper.setWithoutUpdate(world, p, EndBlocks.TENANEA.getBark().defaultBlockState());
}
}
BlockState top = EndBlocks.TENANEA_FLOWERS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.TOP);
BlockState middle = EndBlocks.TENANEA_FLOWERS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.MIDDLE);
BlockState bottom = EndBlocks.TENANEA_FLOWERS.defaultBlockState()
.setValue(BlockProperties.TRIPLE_SHAPE, TripleShape.BOTTOM);
BlockState outer = EndBlocks.TENANEA_OUTER_LEAVES.defaultBlockState();
List<BlockPos> support = Lists.newArrayList();
sphere.addPostProcess((info) -> {
if (random.nextInt(6) == 0 && info.getStateDown().isAir()) {
BlockPos d = info.getPos().below();
support.add(d);
}
if (random.nextInt(5) == 0) {
for (Direction dir : Direction.values()) {
BlockState state = info.getState(dir, 2);
if (state.isAir()) {
return info.getState();
}
}
info.setState(EndBlocks.TENANEA.getBark().defaultBlockState());
}
MHelper.shuffle(DIRECTIONS, random);
for (Direction d : DIRECTIONS) {
if (info.getState(d).isAir()) {
info.setBlockPos(info.getPos().relative(d), outer.setValue(FurBlock.FACING, d));
}
}
if (EndBlocks.TENANEA.isTreeLog(info.getState())) {
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();
});
sphere.fillRecursiveIgnore(world, pos, IGNORE);
BlocksHelper.setWithoutUpdate(world, pos, EndBlocks.TENANEA.getBark());
support.forEach((bpos) -> {
BlockState state = world.getBlockState(bpos);
if (state.isAir() || state.is(EndBlocks.TENANEA_OUTER_LEAVES)) {
int count = MHelper.randRange(3, 8, random);
mut.set(bpos);
if (world.getBlockState(mut.above()).is(EndBlocks.TENANEA_LEAVES)) {
BlocksHelper.setWithoutUpdate(world, mut, top);
for (int i = 1; i < count; i++) {
mut.setY(mut.getY() - 1);
if (world.isEmptyBlock(mut.below())) {
BlocksHelper.setWithoutUpdate(world, mut, middle);
} else {
break;
}
}
BlocksHelper.setWithoutUpdate(world, mut, bottom);
}
}
});
}
static {
REPLACE = (state) -> {
/*if (state.is(CommonBlockTags.END_STONES)) {
return true;
}*/
if (state.getBlock() == EndBlocks.TENANEA_LEAVES) {
return true;
}
if (state.getMaterial().equals(Material.PLANT)) {
return true;
}
return state.getMaterial().isReplaceable();
};
IGNORE = EndBlocks.TENANEA::isTreeLog;
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)
);
}
}

View file

@ -0,0 +1,247 @@
package org.betterx.betterend.world.features.trees;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
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.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.*;
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.blocks.UmbrellaTreeClusterBlock;
import org.betterx.betterend.blocks.UmbrellaTreeMembraneBlock;
import org.betterx.betterend.registry.EndBlocks;
import java.util.List;
import java.util.function.Function;
public class UmbrellaTreeFeature extends DefaultFeature {
private static final Function<BlockState, Boolean> REPLACE;
private static final List<Vector3f> SPLINE;
private static final List<Vector3f> ROOT;
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> featureConfig) {
final RandomSource random = featureConfig.random();
final BlockPos pos = featureConfig.origin();
final WorldGenLevel world = featureConfig.level();
final NoneFeatureConfiguration config = featureConfig.config();
if (!world.getBlockState(pos.below()).is(BlockTags.NYLIUM)) return false;
BlockState wood = EndBlocks.UMBRELLA_TREE.getBark().defaultBlockState();
BlockState membrane = EndBlocks.UMBRELLA_TREE_MEMBRANE.defaultBlockState()
.setValue(UmbrellaTreeMembraneBlock.COLOR, 1);
BlockState center = EndBlocks.UMBRELLA_TREE_MEMBRANE.defaultBlockState()
.setValue(UmbrellaTreeMembraneBlock.COLOR, 0);
BlockState fruit = EndBlocks.UMBRELLA_TREE_CLUSTER.defaultBlockState()
.setValue(UmbrellaTreeClusterBlock.NATURAL, true);
float size = MHelper.randRange(10, 20, random);
int count = (int) (size * 0.15F);
float var = MHelper.PI2 / (float) (count * 3);
float start = MHelper.randRange(0, MHelper.PI2, random);
SDF sdf = null;
List<Center> centers = Lists.newArrayList();
float scale = 1;
if (config != null) {
scale = MHelper.randRange(1F, 1.7F, random);
}
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 * MHelper.randRange(1F, 2F, random), sizeXZ);
// SplineHelper.offset(spline, new Vector3f((20 - size) * 0.2F, 0, 0));
SplineHelper.rotateSpline(spline, angle);
SplineHelper.offsetParts(spline, random, 0.5F, 0, 0.5F);
if (SplineHelper.canGenerate(spline, pos, world, REPLACE)) {
float rScale = (scale - 1) * 0.4F + 1;
SDF branch = SplineHelper.buildSDF(spline, 1.2F * rScale, 0.8F * rScale, (bpos) -> {
return wood;
});
Vector3f vec = spline.get(spline.size() - 1);
float radius = (size + MHelper.randRange(0, size * 0.5F, random)) * 0.4F;
sdf = (sdf == null) ? branch : new SDFUnion().setSourceA(sdf).setSourceB(branch);
SDF mem = makeMembrane(world, radius, random, membrane, center);
float px = MHelper.floor(vec.x()) + 0.5F;
float py = MHelper.floor(vec.y()) + 0.5F;
float pz = MHelper.floor(vec.z()) + 0.5F;
mem = new SDFTranslate().setTranslate(px, py, pz).setSource(mem);
sdf = new SDFSmoothUnion().setRadius(2).setSourceA(sdf).setSourceB(mem);
centers.add(new Center(
pos.getX() + (double) (px * scale),
pos.getY() + (double) (py * scale),
pos.getZ() + (double) (pz * scale),
radius * scale
));
vec = spline.get(0);
}
}
if (sdf == null) {
return false;
}
if (scale > 1) {
sdf = new SDFScale().setScale(scale).setSource(sdf);
}
sdf.setReplaceFunction(REPLACE).addPostProcess((info) -> {
if (EndBlocks.UMBRELLA_TREE.isTreeLog(info.getStateUp()) && EndBlocks.UMBRELLA_TREE.isTreeLog(info.getStateDown())) {
return EndBlocks.UMBRELLA_TREE.getLog().defaultBlockState();
} else if (info.getState().equals(membrane)) {
Center min = centers.get(0);
double d = Double.MAX_VALUE;
BlockPos bpos = info.getPos();
for (Center c : centers) {
double d2 = c.distance(bpos.getX(), bpos.getZ());
if (d2 < d) {
d = d2;
min = c;
}
}
int color = MHelper.floor(d / min.radius * 7);
color = Mth.clamp(color, 1, 7);
return info.getState().setValue(UmbrellaTreeMembraneBlock.COLOR, color);
}
return info.getState();
}).fillRecursive(world, pos);
makeRoots(world, pos, (size * 0.5F + 3) * scale, random, wood);
for (Center c : centers) {
if (!world.getBlockState(new BlockPos(c.px, c.py, c.pz)).isAir()) {
count = MHelper.floor(MHelper.randRange(5F, 10F, random) * scale);
float startAngle = random.nextFloat() * MHelper.PI2;
for (int i = 0; i < count; i++) {
float angle = (float) i / count * MHelper.PI2 + startAngle;
float dist = MHelper.randRange(1.5F, 2.5F, random) * scale;
double px = c.px + Math.sin(angle) * dist;
double pz = c.pz + Math.cos(angle) * dist;
makeFruits(world, px, c.py - 1, pz, fruit, scale);
}
}
}
return true;
}
private void makeRoots(WorldGenLevel world, BlockPos pos, float radius, RandomSource random, BlockState wood) {
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.fillSplineForce(branch, world, wood, pos, REPLACE);
}
}
}
private SDF makeMembrane(WorldGenLevel world,
float radius,
RandomSource random,
BlockState membrane,
BlockState center) {
SDF sphere = new SDFSphere().setRadius(radius).setBlock(membrane);
SDF sub = new SDFTranslate().setTranslate(0, -4, 0).setSource(sphere);
sphere = new SDFSubtraction().setSourceA(sphere).setSourceB(sub);
sphere = new SDFScale3D().setScale(1, 0.5F, 1).setSource(sphere);
sphere = new SDFTranslate().setTranslate(0, 1 - radius * 0.5F, 0).setSource(sphere);
float angle = random.nextFloat() * MHelper.PI2;
int count = (int) MHelper.randRange(radius, radius * 2, random);
if (count < 5) {
count = 5;
}
sphere = new SDFFlatWave().setAngle(angle).setRaysCount(count).setIntensity(0.6F).setSource(sphere);
SDF cent = new SDFSphere().setRadius(2.5F).setBlock(center);
sphere = new SDFUnion().setSourceA(sphere).setSourceB(cent);
return sphere;
}
private void makeFruits(WorldGenLevel world, double px, double py, double pz, BlockState fruit, float scale) {
MutableBlockPos mut = new MutableBlockPos().set(px, py, pz);
for (int i = 0; i < 8; i++) {
mut.move(Direction.DOWN);
if (world.isEmptyBlock(mut)) {
BlockState state = world.getBlockState(mut.above());
if (state.is(EndBlocks.UMBRELLA_TREE_MEMBRANE) && state.getValue(UmbrellaTreeMembraneBlock.COLOR) < 2) {
BlocksHelper.setWithoutUpdate(world, mut, fruit);
}
break;
}
}
}
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(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));
REPLACE = (state) -> {
if (/*state.is(CommonBlockTags.END_STONES) || */state.getMaterial().equals(Material.PLANT) || state.is(
EndBlocks.UMBRELLA_TREE_MEMBRANE)) {
return true;
}
return state.getMaterial().isReplaceable();
};
}
private class Center {
final double px;
final double py;
final double pz;
final float radius;
Center(double x, double y, double z, float radius) {
this.px = x;
this.py = y;
this.pz = z;
this.radius = radius;
}
double distance(float x, float z) {
return MHelper.length(px - x, pz - z);
}
}
}

View file

@ -0,0 +1,5 @@
package org.betterx.betterend.world.generator;
public enum BiomeType {
LAND, VOID
}

View file

@ -0,0 +1,153 @@
package org.betterx.betterend.world.generator;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import org.betterx.betterend.config.Configs;
public class GeneratorOptions {
private static int biomeSizeCaves;
private static boolean hasPortal;
private static boolean hasPillars;
private static boolean hasDragonFights;
private static boolean changeChorusPlant;
private static boolean newGenerator;
private static boolean generateCentralIsland;
private static boolean generateObsidianPlatform;
private static int endCityFailChance;
public static LayerOptions bigOptions;
public static LayerOptions mediumOptions;
public static LayerOptions smallOptions;
private static boolean changeSpawn;
private static BlockPos spawn;
private static boolean replacePortal;
private static boolean replacePillars;
private static int islandDistChunk;
private static boolean directSpikeHeight;
private static int circleRadius = 1000;
private static int circleRadiusSqr;
public static void init() {
biomeSizeCaves = Configs.GENERATOR_CONFIG.getInt("biomeMap", "biomeSizeCaves", 32);
hasPortal = Configs.GENERATOR_CONFIG.getBoolean("portal", "hasPortal", true);
hasPillars = Configs.GENERATOR_CONFIG.getBoolean("spikes", "hasSpikes", true);
hasDragonFights = Configs.GENERATOR_CONFIG.getBooleanRoot("hasDragonFights", true);
changeChorusPlant = Configs.GENERATOR_CONFIG.getBoolean("chorusPlant", "changeChorusPlant", true);
newGenerator = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "useNewGenerator", true);
generateCentralIsland = Configs.GENERATOR_CONFIG.getBoolean("customGenerator", "generateCentralIsland", true);
endCityFailChance = Configs.GENERATOR_CONFIG.getInt("customGenerator", "endCityFailChance", 5);
generateObsidianPlatform = Configs.GENERATOR_CONFIG.getBooleanRoot("generateObsidianPlatform", true);
bigOptions = new LayerOptions(
"customGenerator.layers.bigIslands",
Configs.GENERATOR_CONFIG,
300,
200,
70,
10,
false
);
mediumOptions = new LayerOptions(
"customGenerator.layers.mediumIslands",
Configs.GENERATOR_CONFIG,
150,
100,
70,
20,
true
);
smallOptions = new LayerOptions(
"customGenerator.layers.smallIslands",
Configs.GENERATOR_CONFIG,
60,
50,
70,
30,
false
);
changeSpawn = Configs.GENERATOR_CONFIG.getBoolean("spawn", "changeSpawn", false);
spawn = new BlockPos(
Configs.GENERATOR_CONFIG.getInt("spawn.point", "x", 20),
Configs.GENERATOR_CONFIG.getInt("spawn.point", "y", 65),
Configs.GENERATOR_CONFIG.getInt("spawn.point", "z", 0)
);
replacePortal = Configs.GENERATOR_CONFIG.getBoolean("portal", "customEndPortal", true);
replacePillars = Configs.GENERATOR_CONFIG.getBoolean("spikes", "customObsidianSpikes", true);
circleRadius = Configs.GENERATOR_CONFIG.getInt("customGenerator", "voidRingSize", 1000);
circleRadiusSqr = circleRadius * circleRadius;
islandDistChunk = (circleRadius >> 3); // Twice bigger than normal
}
public static int getBiomeSizeCaves() {
return Mth.clamp(biomeSizeCaves, 1, 8192);
}
public static boolean hasPortal() {
return hasPortal;
}
public static boolean hasPillars() {
return hasPillars;
}
public static boolean hasDragonFights() {
return hasDragonFights;
}
public static boolean changeChorusPlant() {
return changeChorusPlant;
}
public static boolean useNewGenerator() {
return newGenerator;
}
public static boolean hasCentralIsland() {
return generateCentralIsland;
}
public static boolean generateObsidianPlatform() {
return generateObsidianPlatform;
}
public static int getEndCityFailChance() {
return endCityFailChance;
}
public static boolean changeSpawn() {
return changeSpawn;
}
public static BlockPos getSpawn() {
return spawn;
}
public static boolean replacePortal() {
return replacePortal;
}
public static boolean replacePillars() {
return replacePillars;
}
public static int getIslandDistBlock() {
return circleRadius;
}
public static int getIslandDistBlockSqr() {
return circleRadiusSqr;
}
public static int getIslandDistChunk() {
return islandDistChunk;
}
public static void setDirectSpikeHeight() {
directSpikeHeight = true;
}
public static boolean isDirectSpikeHeight() {
boolean height = directSpikeHeight;
directSpikeHeight = false;
return height;
}
}

View file

@ -0,0 +1,192 @@
package org.betterx.betterend.world.generator;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import com.google.common.collect.Maps;
import org.betterx.bclib.sdf.SDF;
import org.betterx.bclib.sdf.operator.SDFRadialNoiseMap;
import org.betterx.bclib.sdf.operator.SDFScale;
import org.betterx.bclib.sdf.operator.SDFSmoothUnion;
import org.betterx.bclib.sdf.operator.SDFTranslate;
import org.betterx.bclib.sdf.primitive.SDFCappedCone;
import org.betterx.bclib.util.MHelper;
import org.betterx.betterend.noise.OpenSimplexNoise;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class IslandLayer {
private static final RandomSource RANDOM = new LegacyRandomSource(MHelper.RANDOM.nextLong());
private final SDFRadialNoiseMap noise;
private final SDF island;
private final List<BlockPos> positions = new ArrayList<BlockPos>(9);
private final Map<BlockPos, SDF> islands = Maps.newHashMap();
private final OpenSimplexNoise density;
private final int seed;
private int lastX = Integer.MIN_VALUE;
private int lastZ = Integer.MIN_VALUE;
private final LayerOptions options;
public IslandLayer(int seed, LayerOptions options) {
this.density = new OpenSimplexNoise(seed);
this.options = options;
this.seed = seed;
SDF cone1 = makeCone(0, 0.4F, 0.2F, -0.3F);
SDF cone2 = makeCone(0.4F, 0.5F, 0.1F, -0.1F);
SDF cone3 = makeCone(0.5F, 0.45F, 0.03F, 0.0F);
SDF cone4 = makeCone(0.45F, 0, 0.02F, 0.03F);
SDF coneBottom = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone1).setSourceB(cone2);
SDF coneTop = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone3).setSourceB(cone4);
noise = (SDFRadialNoiseMap) new SDFRadialNoiseMap().setSeed(seed)
.setRadius(0.5F)
.setIntensity(0.2F)
.setSource(coneTop);
island = new SDFSmoothUnion().setRadius(0.01F).setSourceA(noise).setSourceB(coneBottom);
}
private int getSeed(int x, int z) {
int h = seed + x * 374761393 + z * 668265263;
h = (h ^ (h >> 13)) * 1274126177;
return h ^ (h >> 16);
}
public void updatePositions(double x, double z) {
int ix = MHelper.floor(x / options.distance);
int iz = MHelper.floor(z / options.distance);
if (lastX != ix || lastZ != iz) {
lastX = ix;
lastZ = iz;
positions.clear();
for (int pox = -1; pox < 2; pox++) {
int px = pox + ix;
long px2 = px;
for (int poz = -1; poz < 2; poz++) {
int pz = poz + iz;
long pz2 = pz;
if (px2 * px2 + pz2 * pz2 > options.centerDist) {
RANDOM.setSeed(getSeed(px, pz));
double posX = (px + RANDOM.nextFloat()) * options.distance;
double posY = MHelper.randRange(options.minY, options.maxY, RANDOM);
double posZ = (pz + RANDOM.nextFloat()) * options.distance;
if (density.eval(posX * 0.01, posZ * 0.01) > options.coverage) {
positions.add(new BlockPos(posX, posY, posZ));
}
}
}
}
}
if (GeneratorOptions.hasCentralIsland() && Math.abs(ix) < GeneratorOptions.getIslandDistChunk() && Math.abs(iz) < GeneratorOptions
.getIslandDistChunk()) {
int count = positions.size();
for (int n = 0; n < count; n++) {
BlockPos pos = positions.get(n);
long d = (long) pos.getX() * (long) pos.getX() + (long) pos.getZ() * (long) pos.getZ();
if (d < GeneratorOptions.getIslandDistBlockSqr()) {
positions.remove(n);
count--;
n--;
}
}
if (options.hasCentralIsland) {
positions.add(new BlockPos(0, 64, 0));
}
}
}
private SDF getIsland(BlockPos pos) {
SDF island = islands.get(pos);
if (island == null) {
if (pos.getX() == 0 && pos.getZ() == 0) {
island = new SDFScale().setScale(1.3F).setSource(this.island);
} else {
RANDOM.setSeed(getSeed(pos.getX(), pos.getZ()));
island = new SDFScale().setScale(RANDOM.nextFloat() + 0.5F).setSource(this.island);
}
islands.put(pos, island);
}
noise.setOffset(pos.getX(), pos.getZ());
return island;
}
private float getRelativeDistance(SDF sdf, BlockPos center, double px, double py, double pz) {
float x = (float) (px - center.getX()) / options.scale;
float y = (float) (py - center.getY()) / options.scale;
float z = (float) (pz - center.getZ()) / options.scale;
return sdf.getDistance(x, y, z);
}
private float calculateSDF(double x, double y, double z) {
float distance = 10;
for (BlockPos pos : positions) {
SDF island = getIsland(pos);
float dist = getRelativeDistance(island, pos, x, y, z);
distance = MHelper.min(distance, dist);
}
return distance;
}
public float getDensity(double x, double y, double z) {
return -calculateSDF(x, y, z);
}
public float getDensity(double x, double y, double z, float height) {
noise.setIntensity(height);
noise.setRadius(0.5F / (1 + height));
return -calculateSDF(x, y, z);
}
public void clearCache() {
if (islands.size() > 128) {
islands.clear();
}
}
private static SDF makeCone(float radiusBottom, float radiusTop, float height, float minY) {
float hh = height * 0.5F;
SDF sdf = new SDFCappedCone().setHeight(hh).setRadius1(radiusBottom).setRadius2(radiusTop);
return new SDFTranslate().setTranslate(0, minY + hh, 0).setSource(sdf);
}
/*private static NativeImage loadMap(String path) {
InputStream stream = IslandLayer.class.getResourceAsStream(path);
if (stream != null) {
try {
NativeImage map = NativeImage.read(stream);
stream.close();
return map;
}
catch (IOException e) {
BetterEnd.LOGGER.warning(e.getMessage());
}
}
return null;
}*/
/*static {
NativeImage map = loadMap("/assets/" + BetterEnd.MOD_ID + "/textures/heightmaps/mountain_1.png");
SDF cone1 = makeCone(0, 0.4F, 0.2F, -0.3F);
SDF cone2 = makeCone(0.4F, 0.5F, 0.1F, -0.1F);
SDF cone3 = makeCone(0.5F, 0.45F, 0.03F, 0.0F);
SDF cone4 = makeCone(0.45F, 0, 0.02F, 0.03F);
SDF coneBottom = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone1).setSourceB(cone2);
SDF coneTop = new SDFSmoothUnion().setRadius(0.02F).setSourceA(cone3).setSourceB(cone4);
SDF map1 = new SDFHeightmap().setMap(map).setIntensity(0.3F).setSource(coneTop);
NOISE = (SDFRadialNoiseMap) new SDFRadialNoiseMap().setSource(coneTop);
ISLAND = new SDF[] {
new SDFSmoothUnion().setRadius(0.01F).setSourceA(coneTop).setSourceB(coneBottom),
new SDFSmoothUnion().setRadius(0.01F).setSourceA(map1).setSourceB(coneBottom)
};
}*/
}

View file

@ -0,0 +1,55 @@
package org.betterx.betterend.world.generator;
import net.minecraft.util.Mth;
import org.betterx.bclib.config.PathConfig;
public class LayerOptions {
public final float distance;
public final float scale;
public final float coverage;
public final int center;
public final int heightVariation;
public final int minY;
public final int maxY;
public final long centerDist;
public final boolean hasCentralIsland;
public LayerOptions(String name,
PathConfig config,
float distance,
float scale,
int center,
int heightVariation,
boolean hasCentral) {
this.distance = clampDistance(config.getFloat(name, "distance[1-8192]", distance));
this.scale = clampScale(config.getFloat(name, "scale[0.1-1024]", scale));
this.center = clampCenter(config.getInt(name, "averageHeight[0-255]", center));
this.heightVariation = clampVariation(config.getInt(name, "heightVariation[0-255]", heightVariation));
this.coverage = clampCoverage(config.getFloat(name, "coverage[0-1]", 0.5F));
this.minY = this.center - this.heightVariation;
this.maxY = this.center + this.heightVariation;
this.centerDist = Mth.floor(1000 / this.distance);
this.hasCentralIsland = config.getBoolean(name, "hasCentralIsland", hasCentral);
}
private float clampDistance(float value) {
return Mth.clamp(value, 1, 8192);
}
private float clampScale(float value) {
return Mth.clamp(value, 0.1F, 1024);
}
private float clampCoverage(float value) {
return 0.9999F - Mth.clamp(value, 0, 1) * 2;
}
private int clampCenter(int value) {
return Mth.clamp(value, 0, 255);
}
private int clampVariation(int value) {
return Mth.clamp(value, 0, 255);
}
}

View file

@ -0,0 +1,21 @@
package org.betterx.betterend.world.generator;
public class TerrainBoolCache {
private final byte[] data = new byte[16384];
public static int scaleCoordinate(int value) {
return value >> 7;
}
private int getIndex(int x, int z) {
return x << 7 | z;
}
public void setData(int x, int z, byte value) {
data[getIndex(x & 127, z & 127)] = value;
}
public byte getData(int x, int z) {
return data[getIndex(x & 127, z & 127)];
}
}

Some files were not shown because too many files have changed in this diff Show more