-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Predicates for selecting particular biome selections
- Loading branch information
1 parent
77d709d
commit 35d852e
Showing
14 changed files
with
239 additions
and
0 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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/dev/lukebemish/biomesquisher/surface/AlwaysConditionPredicate.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,22 @@ | ||
package dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
public final class AlwaysConditionPredicate implements ConditionPredicate { | ||
private AlwaysConditionPredicate() {} | ||
|
||
public static final AlwaysConditionPredicate INSTANCE = new AlwaysConditionPredicate(); | ||
|
||
public static final MapCodec<AlwaysConditionPredicate> CODEC = MapCodec.unit(INSTANCE); | ||
|
||
@Override | ||
public MapCodec<? extends ConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
return true; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/dev/lukebemish/biomesquisher/surface/AndConditionPredicate.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 dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
import java.util.List; | ||
|
||
public record AndConditionPredicate(List<ConditionPredicate> predicates) implements ConditionPredicate { | ||
public static final MapCodec<AndConditionPredicate> CODEC = ConditionPredicate.CODEC.listOf().fieldOf("predicates").xmap(AndConditionPredicate::new, AndConditionPredicate::predicates); | ||
|
||
@Override | ||
public MapCodec<AndConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
return predicates.stream().allMatch(p -> p.matches(context, source)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/dev/lukebemish/biomesquisher/surface/BiomeConditionPredicate.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 dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
public record BiomeConditionPredicate(ResourceKey<Biome> key) implements ConditionPredicate { | ||
public static final MapCodec<BiomeConditionPredicate> CODEC = ResourceKey.codec(Registries.BIOME).fieldOf("key").xmap(BiomeConditionPredicate::new, BiomeConditionPredicate::key); | ||
|
||
@Override | ||
public MapCodec<BiomeConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
if (SurfaceRuleModifierUtils.isBiome(source)) { | ||
var predicate = SurfaceRuleModifierUtils.biomeNameTest(source); | ||
return predicate.test(key); | ||
} else { | ||
SurfaceRuleModifierUtils.warnOnNonBiome(context, source); | ||
} | ||
return false; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/dev/lukebemish/biomesquisher/surface/ConditionPredicate.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,17 @@ | ||
package dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.MapCodec; | ||
import dev.lukebemish.biomesquisher.BiomeSquisherRegistries; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
import java.util.function.Function; | ||
|
||
public interface ConditionPredicate { | ||
Codec<ConditionPredicate> CODEC = BiomeSquisherRegistries.SURFACE_CONDITION_PREDICATE_TYPES.byNameCodec() | ||
.dispatch(ConditionPredicate::codec, Function.identity()); | ||
|
||
MapCodec<? extends ConditionPredicate> codec(); | ||
|
||
boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/dev/lukebemish/biomesquisher/surface/IfTruePredicate.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,24 @@ | ||
package dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
public record IfTruePredicate(ConditionPredicate predicate) implements RulePredicate { | ||
public static final MapCodec<IfTruePredicate> CODEC = ConditionPredicate.CODEC.fieldOf("predicate").xmap(IfTruePredicate::new, IfTruePredicate::predicate); | ||
|
||
@Override | ||
public MapCodec<IfTruePredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.RuleSource ruleSource) { | ||
if (SurfaceRuleModifierUtils.isTest(ruleSource)) { | ||
var ifTrue = SurfaceRuleModifierUtils.ifTrue(ruleSource); | ||
return predicate.matches(context, ifTrue); | ||
} else { | ||
SurfaceRuleModifierUtils.warnOnNonTest(context, ruleSource); | ||
} | ||
return false; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/dev/lukebemish/biomesquisher/surface/NeverConditionPredicate.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,22 @@ | ||
package dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
public final class NeverConditionPredicate implements ConditionPredicate { | ||
private NeverConditionPredicate() {} | ||
|
||
public static final NeverConditionPredicate INSTANCE = new NeverConditionPredicate(); | ||
|
||
public static final MapCodec<NeverConditionPredicate> CODEC = MapCodec.unit(INSTANCE); | ||
|
||
@Override | ||
public MapCodec<NeverConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
return false; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/dev/lukebemish/biomesquisher/surface/NotConditionPredicate.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,18 @@ | ||
package dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
public record NotConditionPredicate(ConditionPredicate predicate) implements ConditionPredicate { | ||
public static final MapCodec<NotConditionPredicate> CODEC = ConditionPredicate.CODEC.fieldOf("predicate").xmap(NotConditionPredicate::new, NotConditionPredicate::predicate); | ||
|
||
@Override | ||
public MapCodec<NotConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
return !predicate.matches(context, source); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/dev/lukebemish/biomesquisher/surface/OrConditionPredicate.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 dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
import java.util.List; | ||
|
||
public record OrConditionPredicate(List<ConditionPredicate> predicates) implements ConditionPredicate { | ||
public static final MapCodec<OrConditionPredicate> CODEC = ConditionPredicate.CODEC.listOf().fieldOf("predicates").xmap(OrConditionPredicate::new, OrConditionPredicate::predicates); | ||
|
||
@Override | ||
public MapCodec<OrConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
return predicates.stream().anyMatch(p -> p.matches(context, source)); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/lukebemish/biomesquisher/surface/TypeConditionPredicate.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,21 @@ | ||
package dev.lukebemish.biomesquisher.surface; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
|
||
public record TypeConditionPredicate(ResourceKey<MapCodec<? extends SurfaceRules.ConditionSource>> key) implements ConditionPredicate { | ||
public static final MapCodec<TypeConditionPredicate> CODEC = ResourceKey.codec(Registries.MATERIAL_CONDITION).fieldOf("key").xmap(TypeConditionPredicate::new, TypeConditionPredicate::key); | ||
|
||
@Override | ||
public MapCodec<TypeConditionPredicate> codec() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public boolean matches(RuleModifier.Context context, SurfaceRules.ConditionSource source) { | ||
return BuiltInRegistries.MATERIAL_CONDITION.getResourceKey(source.codec().codec()).orElse(null) == key; | ||
} | ||
} |
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