-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
510 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/megatrex4/ukrainian_dlight/features/Features.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.megatrex4.ukrainian_dlight.features; | ||
|
||
import com.megatrex4.ukrainian_dlight.UkrainianDelight; | ||
import com.megatrex4.ukrainian_dlight.features.features.SaltCavesFeature; | ||
import com.megatrex4.ukrainian_dlight.features.features.config.SaltCavesFeatureConfig; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.world.gen.feature.Feature; | ||
import net.minecraft.world.gen.feature.FeatureConfig; | ||
|
||
public class Features { | ||
|
||
private static <C extends FeatureConfig, F extends Feature<C>> F register(String id, F feature) { | ||
return (F) Registry.register(Registries.FEATURE, UkrainianDelight.id(id), feature); | ||
} | ||
|
||
public final static Feature<SaltCavesFeatureConfig> SALT_CAVES_FEATURE; | ||
|
||
static { | ||
SALT_CAVES_FEATURE = register("salt_caves_feature", new SaltCavesFeature(SaltCavesFeatureConfig.CODEC)); | ||
} | ||
|
||
public static void init() { | ||
new Features(); | ||
} | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
src/main/java/com/megatrex4/ukrainian_dlight/features/features/SaltCavesFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.megatrex4.ukrainian_dlight.features.features; | ||
|
||
|
||
import com.megatrex4.ukrainian_dlight.features.features.config.SaltCavesFeatureConfig; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.StructureWorldAccess; | ||
import net.minecraft.world.gen.feature.Feature; | ||
import net.minecraft.world.gen.feature.util.FeatureContext; | ||
|
||
public class SaltCavesFeature extends Feature<SaltCavesFeatureConfig> { | ||
public SaltCavesFeature(Codec<SaltCavesFeatureConfig> configCodec) { | ||
super(configCodec); | ||
} | ||
|
||
private static final Direction[] DIRECTIONS = {Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST}; | ||
|
||
@Override | ||
public boolean generate(FeatureContext<SaltCavesFeatureConfig> context) { | ||
BlockPos origin = context.getOrigin(); | ||
StructureWorldAccess world = context.getWorld(); | ||
Random random = context.getRandom(); | ||
|
||
SaltCavesFeatureConfig config = context.getConfig(); | ||
int minSize = config.size().getMin(); | ||
int size = config.size().get(random); | ||
int amount = config.amount().get(random); | ||
int spread = config.spread().get(random) / 2; | ||
BlockState innerState = config.innerState(); | ||
BlockState outerState = config.outerState(); | ||
|
||
spread = spread < 16 ? spread : 16; | ||
|
||
if (!world.isAir(origin) || world.isAir(origin.up())) { | ||
return false; | ||
} | ||
|
||
makeOneIcicle(world, origin, size, innerState, outerState, random); | ||
amount -= 1; | ||
|
||
while (amount > 0) { | ||
amount -= 1; | ||
BlockPos.Mutable mutable = origin.mutableCopy(); | ||
mutable = mutable.add(random.nextInt(1 + spread * 2) - spread, 0, random.nextInt(1 + spread * 2) - spread).mutableCopy(); | ||
|
||
boolean bl = false; | ||
|
||
if (world.isAir(mutable) && world.isAir(mutable.up())) { | ||
for (int i = 0; i < 3 && !bl; i += 1) { | ||
mutable = mutable.add(0, 1, 0).mutableCopy(); | ||
|
||
if (world.isAir(mutable) && !world.isAir(mutable.up()) && !world.isAir(mutable.up(2))) { | ||
bl = true; | ||
} | ||
} | ||
} else if (!world.isAir(mutable)) { | ||
for (int i = 0; i < 3 && !bl; i += 1) { | ||
mutable = mutable.add(0, -1, 0).mutableCopy(); | ||
|
||
if (world.isAir(mutable) && !world.isAir(mutable.up()) && !world.isAir(mutable.up(2))) { | ||
bl = true; | ||
} | ||
} | ||
} | ||
|
||
int nextSize = random.nextInt(size) + 1; | ||
nextSize = nextSize > minSize ? nextSize : minSize; | ||
|
||
if (!world.isAir(mutable.up()) && !world.isAir(mutable.up(2))) makeOneIcicle(world, mutable, nextSize, innerState, outerState, random); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static void makeOneIcicle(StructureWorldAccess world, BlockPos origin, int size, BlockState innerState, BlockState outerState, Random random) { | ||
BlockPos.Mutable cursor = origin.mutableCopy(); | ||
|
||
for (int i = 0; i < -1 + (2 * size / 3); i += 1) { | ||
if (world.isAir(cursor)) { | ||
world.setBlockState(cursor, innerState, 0); | ||
} else { | ||
break; | ||
} | ||
|
||
cursor = cursor.down().mutableCopy(); | ||
} | ||
|
||
for (int i = 0; i < 1 + (size / 3); i += 1) { | ||
if (world.isAir(cursor)) { | ||
world.setBlockState(cursor, outerState, 0); | ||
} else { | ||
break; | ||
} | ||
|
||
cursor = cursor.down().mutableCopy(); | ||
} | ||
|
||
if (size > 3) { | ||
for (Direction d : DIRECTIONS) { | ||
if (world.isAir(origin.offset(d)) && !world.isAir(origin.offset(d).up())) makeOneIcicle(world, origin.offset(d), random.nextInt(2 + (size / 3)), innerState, outerState, random); | ||
} | ||
} | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
.../java/com/megatrex4/ukrainian_dlight/features/features/config/SaltCavesFeatureConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.megatrex4.ukrainian_dlight.features.features.config; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.math.intprovider.IntProvider; | ||
import net.minecraft.world.gen.feature.FeatureConfig; | ||
|
||
public record SaltCavesFeatureConfig(IntProvider size, IntProvider amount, IntProvider spread, BlockState innerState, | ||
BlockState outerState) implements FeatureConfig | ||
{ | ||
public static final Codec<SaltCavesFeatureConfig> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
IntProvider.VALUE_CODEC.fieldOf("size").forGetter(SaltCavesFeatureConfig::size), | ||
IntProvider.VALUE_CODEC.fieldOf("amount").forGetter(SaltCavesFeatureConfig::amount), | ||
IntProvider.VALUE_CODEC.fieldOf("spread").forGetter(SaltCavesFeatureConfig::spread), | ||
BlockState.CODEC.fieldOf("inner_state").forGetter(SaltCavesFeatureConfig::innerState), | ||
BlockState.CODEC.fieldOf("outer_state").forGetter(SaltCavesFeatureConfig::outerState) | ||
).apply(instance, instance.stable(SaltCavesFeatureConfig::new))); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/megatrex4/ukrainian_dlight/gen/BiomeKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.megatrex4.ukrainian_dlight.gen; | ||
|
||
import com.megatrex4.ukrainian_dlight.UkrainianDelight; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.world.biome.Biome; | ||
|
||
public class BiomeKeys { | ||
|
||
private static RegistryKey<Biome> register(String name) { | ||
return RegistryKey.of(RegistryKeys.BIOME, UkrainianDelight.id(name)); | ||
} | ||
|
||
public static final RegistryKey<Biome> SALT_CAVES = register("salt_caves"); | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/megatrex4/ukrainian_dlight/gen/CaveBiomes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.megatrex4.ukrainian_dlight.gen; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.source.util.MultiNoiseUtil; | ||
import net.minecraft.world.biome.source.util.MultiNoiseUtil.ParameterRange; | ||
|
||
public class CaveBiomes { | ||
|
||
public static class CaveBiome { | ||
public final ParameterRange temperature, humidity, continentalness, erosion, depth, weirdness; | ||
public final float offset; | ||
public final RegistryKey<Biome> biome; | ||
|
||
public CaveBiome(ParameterRange temperature, ParameterRange humidity, ParameterRange continentalness, ParameterRange erosion, ParameterRange depth, ParameterRange weirdness, float offset, RegistryKey<Biome> biome) { | ||
this.temperature = temperature; | ||
this.humidity = humidity; | ||
this.continentalness = continentalness; | ||
this.erosion = erosion; | ||
this.depth = depth; | ||
this.weirdness = weirdness; | ||
this.offset = offset; | ||
this.biome = biome; | ||
} | ||
|
||
public static CaveBiome of(ParameterRange temperature, ParameterRange humidity, ParameterRange continentalness, ParameterRange erosion, ParameterRange depth, ParameterRange weirdness, float offset, RegistryKey<Biome> biome) { | ||
return new CaveBiome(temperature, humidity, continentalness, erosion, depth, weirdness, offset, biome); | ||
} | ||
} | ||
|
||
private static final MultiNoiseUtil.ParameterRange DEFAULT_PARAMETER = MultiNoiseUtil.ParameterRange.of(-1.0f, 1.0f); | ||
static final ParameterRange ALL_HEIGHT_RANGE = ParameterRange.of(0.2f, 0.9f); | ||
static final ParameterRange ALL_HEIGHT_RANGE_DEEPER = ParameterRange.of(-0.2f, 0.9f); | ||
static final ParameterRange HIGH_RANGE = ParameterRange.of(0.55f, 0.9f); | ||
|
||
public final static ImmutableList<CaveBiome> DEFAULT_CAVE_BIOMES = ImmutableList.of( | ||
// Existing biomes | ||
CaveBiome.of( | ||
ParameterRange.of(-1.0f, -0.6f), | ||
DEFAULT_PARAMETER, | ||
DEFAULT_PARAMETER, | ||
DEFAULT_PARAMETER, | ||
ALL_HEIGHT_RANGE, | ||
ParameterRange.of(0.8f, 1.0f), | ||
0f, | ||
BiomeKeys.SALT_CAVES | ||
) | ||
); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/megatrex4/ukrainian_dlight/mixin/VanillaBiomeParametersMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.megatrex4.ukrainian_dlight.mixin; | ||
|
||
import com.megatrex4.ukrainian_dlight.gen.CaveBiomes; | ||
import com.megatrex4.ukrainian_dlight.gen.CaveBiomes.CaveBiome; | ||
import com.megatrex4.ukrainian_dlight.util.VanillaBiomeParametersHelper; | ||
import com.mojang.datafixers.util.Pair; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.source.util.MultiNoiseUtil; | ||
import net.minecraft.world.biome.source.util.VanillaBiomeParameters; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.function.Consumer; | ||
|
||
@Mixin(VanillaBiomeParameters.class) | ||
public class VanillaBiomeParametersMixin { | ||
@Inject(at = @At("RETURN"), method = "writeCaveBiomes") | ||
private void init(Consumer<Pair<MultiNoiseUtil.NoiseHypercube, RegistryKey<Biome>>> parameters, CallbackInfo info) { | ||
for (CaveBiome b : CaveBiomes.DEFAULT_CAVE_BIOMES) { | ||
VanillaBiomeParametersHelper.writeCaveBiomeParameters(parameters, b.temperature, b.humidity, b.continentalness, b.erosion, b.depth, b.weirdness, b.offset, b.biome); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/megatrex4/ukrainian_dlight/util/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.megatrex4.ukrainian_dlight.util; | ||
|
||
public class Config { | ||
|
||
public boolean generateSaltCaves = true; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/megatrex4/ukrainian_dlight/util/VanillaBiomeParametersHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.megatrex4.ukrainian_dlight.util; | ||
|
||
import com.megatrex4.ukrainian_dlight.gen.BiomeKeys; | ||
import com.mojang.datafixers.util.Pair; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.source.util.MultiNoiseUtil; | ||
|
||
public class VanillaBiomeParametersHelper { | ||
public static void writeCaveBiomeParameters( | ||
java.util.function.Consumer<Pair<MultiNoiseUtil.NoiseHypercube, RegistryKey<Biome>>> parameters, | ||
MultiNoiseUtil.ParameterRange temperature, | ||
MultiNoiseUtil.ParameterRange humidity, | ||
MultiNoiseUtil.ParameterRange continentalness, | ||
MultiNoiseUtil.ParameterRange erosion, | ||
MultiNoiseUtil.ParameterRange depth, | ||
MultiNoiseUtil.ParameterRange weirdness, | ||
float offset, | ||
RegistryKey<Biome> biome) { | ||
|
||
parameters.accept(Pair.of( | ||
MultiNoiseUtil.createNoiseHypercube(temperature, humidity, continentalness, erosion, depth, weirdness, offset), | ||
biome | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/data/ukrainian_delight/tags/worldgen/biome/salt_caves.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"ukrainian_delight:salt_caves" | ||
] | ||
} |
Oops, something went wrong.