Update to surface builder
This commit is contained in:
parent
7f5e27397c
commit
0a3be15ff3
5 changed files with 100 additions and 36 deletions
|
@ -27,6 +27,7 @@ import net.minecraft.world.level.levelgen.GenerationStep;
|
|||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.Noises;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules.SequenceRuleSource;
|
||||
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
|
@ -553,40 +554,13 @@ public class BCLBiomeBuilder {
|
|||
.build());
|
||||
}
|
||||
|
||||
public BCLBiomeBuilder chancedSurface(SurfaceRules.RuleSource surfaceBlockA, SurfaceRules.RuleSource surfaceBlockB, SurfaceRules.RuleSource underBlock){
|
||||
return surface(
|
||||
SurfaceRules.sequence(
|
||||
SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR,
|
||||
SurfaceRules.sequence(
|
||||
SurfaceRules.ifTrue(DoubleBlockSurfaceNoiseCondition.CONDITION, surfaceBlockA),
|
||||
surfaceBlockB
|
||||
)
|
||||
),
|
||||
underBlock
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds surface rule to this biome.
|
||||
* @param newSurfaceRule {link SurfaceRules.RuleSource} surface rule.
|
||||
* @return same {@link BCLBiomeBuilder} instance.
|
||||
*/
|
||||
public BCLBiomeBuilder surface(SurfaceRules.RuleSource newSurfaceRule) {
|
||||
if (this.surfaceRule==null) {
|
||||
this.surfaceRule = newSurfaceRule;
|
||||
} else {
|
||||
this.surfaceRule = SurfaceRules.sequence(this.surfaceRule, newSurfaceRule);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all surface rules
|
||||
* @return same {@link BCLBiomeBuilder} instance.
|
||||
*/
|
||||
public BCLBiomeBuilder clearSurface() {
|
||||
this.surfaceRule = null;
|
||||
this.surfaceRule = newSurfaceRule;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ import net.minecraft.world.level.levelgen.SurfaceRules;
|
|||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||
import net.minecraft.world.level.levelgen.placement.CaveSurface;
|
||||
import ru.bclib.api.biomes.BiomeAPI;
|
||||
import ru.bclib.api.surface.rules.NoiseCondition;
|
||||
import ru.bclib.world.surface.DoubleBlockSurfaceNoiseCondition;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -81,7 +83,7 @@ public class SurfaceRuleBuilder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set biome filler with specified {@link BlockState}. Example - stone in the Overworld biomes.
|
||||
* Set biome filler with specified {@link BlockState}. Example - stone in the Overworld biomes. The rule is added with priority 3.
|
||||
* @param state {@link BlockState} for filling.
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
|
@ -92,21 +94,68 @@ public class SurfaceRuleBuilder {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set biome ceiling with specified {@link BlockState}. Example - block of sandstone in the Overworld desert in air pockets.
|
||||
* Set biome floor with specified {@link BlockState}. Example - underside of a gravel floor. The rule is added with priority 3.
|
||||
* @param state {@link BlockState} for the ground cover.
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
public SurfaceRuleBuilder ceil(BlockState state) {
|
||||
entryInstance = getFromCache("ceil_" + state.toString(), () -> {
|
||||
public SurfaceRuleBuilder floor(BlockState state) {
|
||||
entryInstance = getFromCache("floor_" + state.toString(), () -> {
|
||||
RuleSource rule = SurfaceRules.state(state);
|
||||
return new SurfaceRuleEntry(2, SurfaceRules.ifTrue(SurfaceRules.ON_CEILING, rule));
|
||||
return new SurfaceRuleEntry(3, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule));
|
||||
});
|
||||
rules.add(entryInstance);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome ceiling material with specified {@link BlockState} and height. Example - sandstone in the Overworld deserts.
|
||||
* Set biome floor material with specified {@link BlockState} and height. The rule is added with priority 3.
|
||||
* @param state {@link BlockState} for the subterrain layer.
|
||||
* @param height block layer height.
|
||||
* @param noise The noise object that is applied
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
public SurfaceRuleBuilder belowFloor(BlockState state, int height, NoiseCondition noise) {
|
||||
entryInstance = getFromCache("below_floor_" + height + "_" + state.toString() + "_" + noise.getClass().getSimpleName(), () -> {
|
||||
RuleSource rule = SurfaceRules.state(state);
|
||||
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule));
|
||||
return new SurfaceRuleEntry(3, rule);
|
||||
});
|
||||
rules.add(entryInstance);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome floor material with specified {@link BlockState} and height. The rule is added with priority 3.
|
||||
* @param state {@link BlockState} for the subterrain layer.
|
||||
* @param height block layer height.
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
public SurfaceRuleBuilder belowFloor(BlockState state, int height) {
|
||||
entryInstance = getFromCache("below_floor_" + height + "_" + state.toString(), () -> {
|
||||
RuleSource rule = SurfaceRules.state(state);
|
||||
rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), rule);
|
||||
return new SurfaceRuleEntry(3, rule);
|
||||
});
|
||||
rules.add(entryInstance);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome ceiling with specified {@link BlockState}. Example - block of sandstone in the Overworld desert in air pockets. The rule is added with priority 3.
|
||||
* @param state {@link BlockState} for the ground cover.
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
public SurfaceRuleBuilder ceil(BlockState state) {
|
||||
entryInstance = getFromCache("ceil_" + state.toString(), () -> {
|
||||
RuleSource rule = SurfaceRules.state(state);
|
||||
return new SurfaceRuleEntry(3, SurfaceRules.ifTrue(SurfaceRules.ON_CEILING, rule));
|
||||
});
|
||||
rules.add(entryInstance);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome ceiling material with specified {@link BlockState} and height. Example - sandstone in the Overworld deserts. The rule is added with priority 3.
|
||||
* @param state {@link BlockState} for the subterrain layer.
|
||||
* @param height block layer height.
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
|
@ -159,6 +208,39 @@ public class SurfaceRuleBuilder {
|
|||
return rule(7, rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome floor with specified {@link BlockState} and the {@link DoubleBlockSurfaceNoiseCondition}. The rule is added with priority 3.
|
||||
* @param surfaceBlockA {@link BlockState} for the ground cover.
|
||||
* @param surfaceBlockB {@link BlockState} for the alternative ground cover.
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
public SurfaceRuleBuilder chancedFloor(BlockState surfaceBlockA, BlockState surfaceBlockB){
|
||||
return chancedFloor(surfaceBlockA, surfaceBlockB, DoubleBlockSurfaceNoiseCondition.CONDITION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome floor with specified {@link BlockState} and the given Noise Function. The rule is added with priority 3.
|
||||
* @param surfaceBlockA {@link BlockState} for the ground cover.
|
||||
* @param surfaceBlockB {@link BlockState} for the alternative ground cover.
|
||||
* @param noise The {@link NoiseCondition}
|
||||
* @return same {@link SurfaceRuleBuilder} instance.
|
||||
*/
|
||||
public SurfaceRuleBuilder chancedFloor(BlockState surfaceBlockA, BlockState surfaceBlockB, NoiseCondition noise){
|
||||
entryInstance = getFromCache("chancedFloor_" + surfaceBlockA + "_" + surfaceBlockB + "_" + noise.getClass().getSimpleName(), () -> {
|
||||
RuleSource rule =
|
||||
SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR,
|
||||
SurfaceRules.sequence(
|
||||
SurfaceRules.ifTrue(noise, SurfaceRules.state(surfaceBlockA)),
|
||||
SurfaceRules.state(surfaceBlockB)
|
||||
)
|
||||
)
|
||||
;
|
||||
return new SurfaceRuleEntry(4, rule);
|
||||
});
|
||||
rules.add(entryInstance);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalise rule building process.
|
||||
* @return {@link SurfaceRules.RuleSource}.
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package ru.bclib.api.surface.rules;
|
||||
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import ru.bclib.mixin.common.SurfaceRulesContextAccessor;
|
||||
|
||||
public interface NoiseCondition extends SurfaceRules.ConditionSource{
|
||||
boolean test(SurfaceRulesContextAccessor context);
|
||||
}
|
|
@ -8,7 +8,7 @@ import net.minecraft.world.level.levelgen.SurfaceRules.Context;
|
|||
import net.minecraft.world.level.levelgen.SurfaceRules.LazyXZCondition;
|
||||
import ru.bclib.mixin.common.SurfaceRulesContextAccessor;
|
||||
|
||||
public abstract class SurfaceNoiseCondition implements SurfaceRules.ConditionSource{
|
||||
public abstract class SurfaceNoiseCondition implements NoiseCondition{
|
||||
@Override
|
||||
public Codec<? extends ConditionSource> codec() {
|
||||
return SurfaceRules.ConditionSource.CODEC;
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.world.level.levelgen.SurfaceRules.Context;
|
|||
import net.minecraft.world.level.levelgen.SurfaceRules.LazyCondition;
|
||||
import ru.bclib.mixin.common.SurfaceRulesContextAccessor;
|
||||
|
||||
public abstract class VolumeNoiseCondition implements SurfaceRules.ConditionSource{
|
||||
public abstract class VolumeNoiseCondition implements NoiseCondition{
|
||||
@Override
|
||||
public Codec<? extends ConditionSource> codec() {
|
||||
return SurfaceRules.ConditionSource.CODEC;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue