From eba384ec9d025de96f861455a91373f60f239d70 Mon Sep 17 00:00:00 2001 From: Zepalesque <60141811+Zepalesque@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:59:11 -0500 Subject: [PATCH] fix: allow tag usage --- gradle.properties | 2 +- .../api/block/predicate/InBiomePredicate.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 25b39bc..c94e5a3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.debug=false # Version -mod_version=1.2.15 +mod_version=1.2.16 # Mod mod_id=zenith diff --git a/src/main/java/net/zepalesque/zenith/api/block/predicate/InBiomePredicate.java b/src/main/java/net/zepalesque/zenith/api/block/predicate/InBiomePredicate.java index 12b5add..f3815bf 100644 --- a/src/main/java/net/zepalesque/zenith/api/block/predicate/InBiomePredicate.java +++ b/src/main/java/net/zepalesque/zenith/api/block/predicate/InBiomePredicate.java @@ -1,23 +1,24 @@ package net.zepalesque.zenith.api.block.predicate; +import com.mojang.datafixers.util.Either; +import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.core.RegistryCodecs; -import net.minecraft.core.Vec3i; import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicate; import net.minecraft.world.level.levelgen.blockpredicates.BlockPredicateType; -import net.minecraft.world.phys.shapes.Shapes; import net.zepalesque.zenith.core.registry.ZenithBlockPredicates; -public record InBiomePredicate(HolderSet biomes) implements BlockPredicate { +public record InBiomePredicate(Either, TagKey> biomes) implements BlockPredicate { public static MapCodec CODEC = RecordCodecBuilder.mapCodec(builder -> builder.group( - RegistryCodecs.homogeneousList(Registries.BIOME).fieldOf("biomes").forGetter(InBiomePredicate::biomes)) + Codec.either(RegistryCodecs.homogeneousList(Registries.BIOME), TagKey.hashedCodec(Registries.BIOME)).fieldOf("biomes").forGetter(InBiomePredicate::biomes)) .apply(builder, InBiomePredicate::new) ); @@ -27,6 +28,15 @@ public BlockPredicateType type() { } public boolean test(WorldGenLevel level, BlockPos pos) { - return this.biomes.contains(level.getBiome(pos)); + Holder biome = level.getBiome(pos); + return this.biomes.map(holders -> holders.contains(biome), biome::is); + } + + public static InBiomePredicate inTag(TagKey tag) { + return new InBiomePredicate(Either.right(tag)); + } + + public static InBiomePredicate inSet(HolderSet set) { + return new InBiomePredicate(Either.left(set)); } }