Skip to content

Commit

Permalink
fix: allow tag usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jan 17, 2025
1 parent 64fcb4f commit eba384e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.debug=false


# Version
mod_version=1.2.15
mod_version=1.2.16

# Mod
mod_id=zenith
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Biome> biomes) implements BlockPredicate {
public record InBiomePredicate(Either<HolderSet<Biome>, TagKey<Biome>> biomes) implements BlockPredicate {
public static MapCodec<InBiomePredicate> 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)
);

Expand All @@ -27,6 +28,15 @@ public BlockPredicateType<?> type() {
}

public boolean test(WorldGenLevel level, BlockPos pos) {
return this.biomes.contains(level.getBiome(pos));
Holder<Biome> biome = level.getBiome(pos);
return this.biomes.map(holders -> holders.contains(biome), biome::is);
}

public static InBiomePredicate inTag(TagKey<Biome> tag) {
return new InBiomePredicate(Either.right(tag));
}

public static InBiomePredicate inSet(HolderSet<Biome> set) {
return new InBiomePredicate(Either.left(set));
}
}

0 comments on commit eba384e

Please sign in to comment.