- Fix a bug with the River carver
- Add '/terra defaults set' command - Add extra checks to make sure terrain modules are clamped between 0.0-1.0
This commit is contained in:
parent
4d936f9f5d
commit
8269adddbb
@ -54,7 +54,7 @@ public class RiverSettings {
|
||||
@Comment("Controls the depth of the river")
|
||||
public int bedDepth;
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Range(min = 0, max = 10)
|
||||
@Comment("Controls the height of river banks")
|
||||
public int minBankHeight;
|
||||
|
||||
|
@ -28,6 +28,7 @@ package com.terraforged.core.settings;
|
||||
import com.terraforged.core.util.serialization.annotation.Comment;
|
||||
import com.terraforged.core.util.serialization.annotation.Range;
|
||||
import com.terraforged.core.util.serialization.annotation.Serializable;
|
||||
import com.terraforged.core.world.terrain.TerrainPopulator;
|
||||
import me.dags.noise.Module;
|
||||
|
||||
@Serializable
|
||||
@ -83,10 +84,8 @@ public class TerrainSettings {
|
||||
public Module apply(double bias, double scale, Module module) {
|
||||
double moduleBias = bias * baseScale;
|
||||
double moduleScale = scale * verticalScale;
|
||||
if (moduleBias + moduleScale > 1) {
|
||||
return module.scale(moduleScale).bias(moduleBias).clamp(0, 1);
|
||||
}
|
||||
return module.scale(moduleScale).bias(moduleBias);
|
||||
Module outputModule = module.scale(moduleScale).bias(moduleBias);
|
||||
return TerrainPopulator.clamp(outputModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +177,9 @@ public class River extends TerrainPopulator {
|
||||
}
|
||||
|
||||
private void carveBed(Cell<Terrain> cell, float bedAlpha, float bedHeight) {
|
||||
// lerp the height down to the riverbed height
|
||||
cell.value = NoiseUtil.lerp(cell.value, bedHeight, bedAlpha);
|
||||
if (cell.value > bedHeight) {
|
||||
cell.value = NoiseUtil.lerp(cell.value, bedHeight, bedAlpha);
|
||||
}
|
||||
tag(cell, terrains.river);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class TerrainPopulator implements Populator {
|
||||
|
||||
public TerrainPopulator(Module source, Terrain type) {
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
this.source = clamp(source);
|
||||
}
|
||||
|
||||
public Module getSource() {
|
||||
@ -57,4 +57,11 @@ public class TerrainPopulator implements Populator {
|
||||
public void tag(Cell<Terrain> cell, float x, float y) {
|
||||
cell.tag = type;
|
||||
}
|
||||
|
||||
public static Module clamp(Module module) {
|
||||
if (module.minValue() < 0 || module.maxValue() > 1) {
|
||||
return module.clamp(0, 1);
|
||||
}
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,8 @@ public class StandardTerrainProvider implements TerrainProvider {
|
||||
Terrain type = new Terrain(name, id, weight);
|
||||
Module combined = Source.perlin(seed.next(), scale, 1)
|
||||
.warp(seed.next(), scale / 2, 2, scale / 2D)
|
||||
.blend(tp1.getSource(), tp2.getSource(), 0.5, 0.25);
|
||||
.blend(tp1.getSource(), tp2.getSource(), 0.5, 0.25)
|
||||
.clamp(0, 1);
|
||||
|
||||
return new TerrainPopulator(combined, type);
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import com.terraforged.mod.command.search.BothSearchTask;
|
||||
import com.terraforged.mod.command.search.Search;
|
||||
import com.terraforged.mod.command.search.TerrainSearchTask;
|
||||
import com.terraforged.mod.data.DataGen;
|
||||
import com.terraforged.mod.settings.SettingsHelper;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@ -94,6 +95,9 @@ public class TerraCommand {
|
||||
.then(Commands.literal("data")
|
||||
.then(Commands.literal("dump")
|
||||
.executes(TerraCommand::dump)))
|
||||
.then(Commands.literal("defaults")
|
||||
.then(Commands.literal("set")
|
||||
.executes(TerraCommand::setDefaults)))
|
||||
.then(Commands.literal("debug")
|
||||
.executes(TerraCommand::debugBiome))
|
||||
.then(Commands.literal("locate")
|
||||
@ -134,6 +138,20 @@ public class TerraCommand {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int setDefaults(CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||
TerraContext terraContext = getContext(context).orElseThrow(() -> createException(
|
||||
"Invalid world type",
|
||||
"This command can only be run in a TerraForged world!"
|
||||
));
|
||||
|
||||
context.getSource().sendFeedback(
|
||||
new StringTextComponent("Setting generator defaults"),
|
||||
true
|
||||
);
|
||||
SettingsHelper.exportDefaults(terraContext.terraSettings);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private static int debugBiome(CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||
ServerPlayerEntity player = context.getSource().asPlayer();
|
||||
BlockPos position = player.getPosition();
|
||||
|
Loading…
Reference in New Issue
Block a user