- 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")
|
@Comment("Controls the depth of the river")
|
||||||
public int bedDepth;
|
public int bedDepth;
|
||||||
|
|
||||||
@Range(min = 1, max = 10)
|
@Range(min = 0, max = 10)
|
||||||
@Comment("Controls the height of river banks")
|
@Comment("Controls the height of river banks")
|
||||||
public int minBankHeight;
|
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.Comment;
|
||||||
import com.terraforged.core.util.serialization.annotation.Range;
|
import com.terraforged.core.util.serialization.annotation.Range;
|
||||||
import com.terraforged.core.util.serialization.annotation.Serializable;
|
import com.terraforged.core.util.serialization.annotation.Serializable;
|
||||||
|
import com.terraforged.core.world.terrain.TerrainPopulator;
|
||||||
import me.dags.noise.Module;
|
import me.dags.noise.Module;
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -83,10 +84,8 @@ public class TerrainSettings {
|
|||||||
public Module apply(double bias, double scale, Module module) {
|
public Module apply(double bias, double scale, Module module) {
|
||||||
double moduleBias = bias * baseScale;
|
double moduleBias = bias * baseScale;
|
||||||
double moduleScale = scale * verticalScale;
|
double moduleScale = scale * verticalScale;
|
||||||
if (moduleBias + moduleScale > 1) {
|
Module outputModule = module.scale(moduleScale).bias(moduleBias);
|
||||||
return module.scale(moduleScale).bias(moduleBias).clamp(0, 1);
|
return TerrainPopulator.clamp(outputModule);
|
||||||
}
|
|
||||||
return module.scale(moduleScale).bias(moduleBias);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,8 +177,9 @@ public class River extends TerrainPopulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void carveBed(Cell<Terrain> cell, float bedAlpha, float bedHeight) {
|
private void carveBed(Cell<Terrain> cell, float bedAlpha, float bedHeight) {
|
||||||
// lerp the height down to the riverbed height
|
if (cell.value > bedHeight) {
|
||||||
cell.value = NoiseUtil.lerp(cell.value, bedHeight, bedAlpha);
|
cell.value = NoiseUtil.lerp(cell.value, bedHeight, bedAlpha);
|
||||||
|
}
|
||||||
tag(cell, terrains.river);
|
tag(cell, terrains.river);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class TerrainPopulator implements Populator {
|
|||||||
|
|
||||||
public TerrainPopulator(Module source, Terrain type) {
|
public TerrainPopulator(Module source, Terrain type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.source = source;
|
this.source = clamp(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Module getSource() {
|
public Module getSource() {
|
||||||
@ -57,4 +57,11 @@ public class TerrainPopulator implements Populator {
|
|||||||
public void tag(Cell<Terrain> cell, float x, float y) {
|
public void tag(Cell<Terrain> cell, float x, float y) {
|
||||||
cell.tag = type;
|
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);
|
Terrain type = new Terrain(name, id, weight);
|
||||||
Module combined = Source.perlin(seed.next(), scale, 1)
|
Module combined = Source.perlin(seed.next(), scale, 1)
|
||||||
.warp(seed.next(), scale / 2, 2, scale / 2D)
|
.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);
|
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.Search;
|
||||||
import com.terraforged.mod.command.search.TerrainSearchTask;
|
import com.terraforged.mod.command.search.TerrainSearchTask;
|
||||||
import com.terraforged.mod.data.DataGen;
|
import com.terraforged.mod.data.DataGen;
|
||||||
|
import com.terraforged.mod.settings.SettingsHelper;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@ -94,6 +95,9 @@ public class TerraCommand {
|
|||||||
.then(Commands.literal("data")
|
.then(Commands.literal("data")
|
||||||
.then(Commands.literal("dump")
|
.then(Commands.literal("dump")
|
||||||
.executes(TerraCommand::dump)))
|
.executes(TerraCommand::dump)))
|
||||||
|
.then(Commands.literal("defaults")
|
||||||
|
.then(Commands.literal("set")
|
||||||
|
.executes(TerraCommand::setDefaults)))
|
||||||
.then(Commands.literal("debug")
|
.then(Commands.literal("debug")
|
||||||
.executes(TerraCommand::debugBiome))
|
.executes(TerraCommand::debugBiome))
|
||||||
.then(Commands.literal("locate")
|
.then(Commands.literal("locate")
|
||||||
@ -134,6 +138,20 @@ public class TerraCommand {
|
|||||||
return Command.SINGLE_SUCCESS;
|
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 {
|
private static int debugBiome(CommandContext<CommandSource> context) throws CommandSyntaxException {
|
||||||
ServerPlayerEntity player = context.getSource().asPlayer();
|
ServerPlayerEntity player = context.getSource().asPlayer();
|
||||||
BlockPos position = player.getPosition();
|
BlockPos position = player.getPosition();
|
||||||
|
Loading…
Reference in New Issue
Block a user