-
-
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
30 changed files
with
408 additions
and
138 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
common/src/main/java/dev/tocraft/crafted/ctgen/CTerrainGeneration.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
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
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
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
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
55 changes: 50 additions & 5 deletions
55
common/src/main/java/dev/tocraft/crafted/ctgen/layer/BlockLayer.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 |
---|---|---|
@@ -1,27 +1,72 @@ | ||
package dev.tocraft.crafted.ctgen.layer; | ||
|
||
import com.mojang.serialization.Codec; | ||
import dev.tocraft.crafted.ctgen.blockplacer.BasicPlacer; | ||
import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; | ||
import dev.tocraft.crafted.ctgen.util.CTRegistries; | ||
import dev.tocraft.crafted.ctgen.zone.Zone; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.world.level.levelgen.synth.SimplexNoise; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
public abstract class BlockLayer { | ||
public static final Codec<BlockLayer> CODEC = CTRegistries.BLOCK_LAYER.byNameCodec().dispatchStable(BlockLayer::codec, Function.identity()); | ||
private final String name; | ||
private final boolean hasCaves; | ||
private final BlockPlacer fallback; | ||
|
||
protected final String name; | ||
|
||
public BlockLayer(String name) { | ||
public BlockLayer(String name, boolean hasCaves, BlockPlacer fallback) { | ||
this.name = name; | ||
this.hasCaves = hasCaves; | ||
this.fallback = fallback; | ||
} | ||
|
||
public static void register() { | ||
Registry.register(CTRegistries.BLOCK_LAYER, SeaLayer.ID, SeaLayer.CODEC); | ||
Registry.register(CTRegistries.BLOCK_LAYER, HeightLayer.ID, HeightLayer.CODEC); | ||
Registry.register(CTRegistries.BLOCK_LAYER, WeightLayer.ID, WeightLayer.CODEC); | ||
} | ||
|
||
public static BlockLayer deepslate(int minY) { | ||
return new HeightLayer(minY, 0, true, "deepslate", BasicPlacer.DEEPSLATE_BLOCK); | ||
} | ||
|
||
public static BlockLayer stone() { | ||
return new WeightLayer(0, 0.96, "stone", BasicPlacer.STONE_BLOCK); | ||
} | ||
|
||
public static BlockLayer dirt() { | ||
// max is 200% to ensure there's no gap caused by "shifted" blocks | ||
return new WeightLayer(0.96, 2, "dirt", BasicPlacer.DIRT_BLOCK); | ||
} | ||
|
||
public abstract boolean is(SimplexNoise noise, double x, double y, double z); | ||
public static BlockLayer surface() { | ||
return new SurfaceLayer("surface", BasicPlacer.GRASS_BLOCK); | ||
} | ||
|
||
public static BlockLayer sea() { | ||
return new SeaLayer("sea", BasicPlacer.WATER_BLOCK); | ||
} | ||
|
||
public static List<BlockLayer> defaultLayers(int minY) { | ||
return List.of(surface(), deepslate(minY), sea(), stone(), dirt()); | ||
} | ||
|
||
public abstract boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift); | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
; | ||
public boolean hasCaves() { | ||
return hasCaves; | ||
} | ||
|
||
public BlockPlacer getFallback() { | ||
return fallback; | ||
} | ||
|
||
protected abstract Codec<? extends BlockLayer> codec(); | ||
} |
76 changes: 76 additions & 0 deletions
76
common/src/main/java/dev/tocraft/crafted/ctgen/layer/HeightLayer.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,76 @@ | ||
package dev.tocraft.crafted.ctgen.layer; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import dev.tocraft.crafted.ctgen.CTerrainGeneration; | ||
import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; | ||
import dev.tocraft.crafted.ctgen.zone.Zone; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.synth.SimplexNoise; | ||
|
||
@SuppressWarnings("unused") | ||
public class HeightLayer extends BlockLayer { | ||
private final int min; | ||
private final int max; | ||
private final boolean limitedToSurface; | ||
private final boolean hasShift; | ||
|
||
public HeightLayer(int minY, int maxY, String name, BlockPlacer fallback) { | ||
this(minY, maxY, true, name, fallback); | ||
} | ||
|
||
public HeightLayer(int minY, int maxY, boolean hasShift, String name, BlockPlacer fallback) { | ||
this(minY, maxY, hasShift, name, true, fallback); | ||
} | ||
|
||
public HeightLayer(int minY, int maxY, boolean hasShift, String name, boolean hasCaves, BlockPlacer fallback) { | ||
this(minY, maxY, true, hasShift, name, hasCaves, fallback); | ||
} | ||
|
||
public HeightLayer(int minY, int maxY, boolean limitedToSurface, boolean hasShift, String name, boolean hasCaves, BlockPlacer fallback) { | ||
super(name, hasCaves, fallback); | ||
this.min = minY; | ||
this.max = maxY; | ||
this.hasShift = hasShift; | ||
this.limitedToSurface = limitedToSurface; | ||
} | ||
|
||
public int getMaxY() { | ||
return max; | ||
} | ||
|
||
public int getMinY() { | ||
return min; | ||
} | ||
|
||
public boolean hasShift() { | ||
return hasShift; | ||
} | ||
|
||
public boolean isLimitedToSurface() { | ||
return limitedToSurface; | ||
} | ||
|
||
@Override | ||
public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { | ||
int y2 = hasShift ? y + shift : y; | ||
return y2 >= min - 1 && y2 <= max && (!limitedToSurface || y < surfaceHeight); | ||
} | ||
|
||
public static final Codec<HeightLayer> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.INT.fieldOf("min").forGetter(HeightLayer::getMinY), | ||
Codec.INT.fieldOf("max").forGetter(HeightLayer::getMaxY), | ||
Codec.BOOL.optionalFieldOf("limit_to_surface", true).forGetter(HeightLayer::isLimitedToSurface), | ||
Codec.BOOL.optionalFieldOf("shift", true).forGetter(HeightLayer::hasShift), | ||
Codec.STRING.fieldOf("name").forGetter(BlockLayer::getName), | ||
Codec.BOOL.optionalFieldOf("has_caves", true).forGetter(BlockLayer::hasCaves), | ||
BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) | ||
).apply(instance, instance.stable(HeightLayer::new))); | ||
|
||
public static final ResourceLocation ID = CTerrainGeneration.id("height"); | ||
|
||
@Override | ||
protected Codec<HeightLayer> codec() { | ||
return CODEC; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
common/src/main/java/dev/tocraft/crafted/ctgen/layer/SeaLayer.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,32 @@ | ||
package dev.tocraft.crafted.ctgen.layer; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import dev.tocraft.crafted.ctgen.CTerrainGeneration; | ||
import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; | ||
import dev.tocraft.crafted.ctgen.zone.Zone; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.synth.SimplexNoise; | ||
|
||
public class SeaLayer extends BlockLayer { | ||
public SeaLayer(String name, BlockPlacer fallback) { | ||
super(name, false, fallback); | ||
} | ||
|
||
@Override | ||
public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { | ||
return y > surfaceHeight && surfaceHeight < seaLevel; | ||
} | ||
|
||
public static final Codec<SeaLayer> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.STRING.fieldOf("name").forGetter(BlockLayer::getName), | ||
BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) | ||
).apply(instance, instance.stable(SeaLayer::new))); | ||
|
||
public static final ResourceLocation ID = CTerrainGeneration.id("sea"); | ||
|
||
@Override | ||
protected Codec<SeaLayer> codec() { | ||
return CODEC; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
common/src/main/java/dev/tocraft/crafted/ctgen/layer/SurfaceLayer.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,37 @@ | ||
package dev.tocraft.crafted.ctgen.layer; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import dev.tocraft.crafted.ctgen.CTerrainGeneration; | ||
import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; | ||
import dev.tocraft.crafted.ctgen.zone.Zone; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.synth.SimplexNoise; | ||
|
||
public class SurfaceLayer extends BlockLayer { | ||
public SurfaceLayer(String name, BlockPlacer fallback) { | ||
this(name, true, fallback); | ||
} | ||
|
||
public SurfaceLayer(String name, boolean hasCaves, BlockPlacer fallback) { | ||
super(name, hasCaves, fallback); | ||
} | ||
|
||
@Override | ||
public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { | ||
return y == (int) surfaceHeight; | ||
} | ||
|
||
public static final Codec<SurfaceLayer> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.STRING.optionalFieldOf("name", "surface").forGetter(BlockLayer::getName), | ||
Codec.BOOL.optionalFieldOf("has_caves", true).forGetter(BlockLayer::hasCaves), | ||
BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) | ||
).apply(instance, instance.stable(SurfaceLayer::new))); | ||
|
||
public static final ResourceLocation ID = CTerrainGeneration.id("sea"); | ||
|
||
@Override | ||
protected Codec<SurfaceLayer> codec() { | ||
return CODEC; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
common/src/main/java/dev/tocraft/crafted/ctgen/layer/WeightLayer.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,65 @@ | ||
package dev.tocraft.crafted.ctgen.layer; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import dev.tocraft.crafted.ctgen.CTerrainGeneration; | ||
import dev.tocraft.crafted.ctgen.blockplacer.BlockPlacer; | ||
import dev.tocraft.crafted.ctgen.zone.Zone; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.levelgen.synth.SimplexNoise; | ||
|
||
public class WeightLayer extends BlockLayer { | ||
private final double min; | ||
private final double max; | ||
private final boolean hasShift; | ||
|
||
public WeightLayer(double minPercentage, double maxPercentage, String name, BlockPlacer fallback) { | ||
this(minPercentage, maxPercentage, true, name, fallback); | ||
} | ||
|
||
public WeightLayer(double minPercentage, double maxPercentage, boolean hasShift, String name, BlockPlacer fallback) { | ||
this(minPercentage, maxPercentage, hasShift, name, true, fallback); | ||
} | ||
|
||
public WeightLayer(double minPercentage, double maxPercentage, boolean hasShift, String name, boolean hasCaves, BlockPlacer fallback) { | ||
super(name, hasCaves, fallback); | ||
this.min = minPercentage; | ||
this.max = maxPercentage; | ||
this.hasShift = hasShift; | ||
} | ||
|
||
public double getMaxPercentage() { | ||
return max; | ||
} | ||
|
||
public double getMinPercentage() { | ||
return min; | ||
} | ||
|
||
public boolean hasShift() { | ||
return hasShift; | ||
} | ||
|
||
@Override | ||
public boolean is(SimplexNoise noise, int x, int y, int z, Zone zone, int minY, int seaLevel, double surfaceHeight, int genHeight, int shift) { | ||
int y2 = hasShift ? y + shift : y; | ||
double percentage = (y2 - minY) / (surfaceHeight - minY); | ||
return this.min <= percentage && percentage <= this.max; | ||
} | ||
|
||
public static final Codec<WeightLayer> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.DOUBLE.fieldOf("min_percentage").forGetter(WeightLayer::getMinPercentage), | ||
Codec.DOUBLE.fieldOf("max_percentage").forGetter(WeightLayer::getMaxPercentage), | ||
Codec.BOOL.optionalFieldOf("shift", true).forGetter(WeightLayer::hasShift), | ||
Codec.STRING.fieldOf("name").forGetter(BlockLayer::getName), | ||
Codec.BOOL.optionalFieldOf("has_caves", true).forGetter(BlockLayer::hasCaves), | ||
BlockPlacer.CODEC.fieldOf("fallback").forGetter(BlockLayer::getFallback) | ||
).apply(instance, instance.stable(WeightLayer::new))); | ||
|
||
public static final ResourceLocation ID = CTerrainGeneration.id("weight"); | ||
|
||
@Override | ||
protected Codec<WeightLayer> codec() { | ||
return CODEC; | ||
} | ||
} |
Oops, something went wrong.