diff --git a/src/main/java/org/betterx/bclib/BCLib.java b/src/main/java/org/betterx/bclib/BCLib.java index ce54b584..e212bf9f 100644 --- a/src/main/java/org/betterx/bclib/BCLib.java +++ b/src/main/java/org/betterx/bclib/BCLib.java @@ -12,6 +12,7 @@ import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry; import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; import org.betterx.bclib.api.v2.levelgen.structures.TemplatePiece; import org.betterx.bclib.api.v2.levelgen.surface.rules.Conditions; +import org.betterx.bclib.api.v2.poi.PoiManager; import org.betterx.bclib.api.v3.levelgen.features.blockpredicates.BlockPredicates; import org.betterx.bclib.api.v3.levelgen.features.placement.PlacementModifiers; import org.betterx.bclib.commands.CommandRegistry; @@ -61,6 +62,7 @@ public class BCLib implements ModInitializer { AnvilRecipe.register(); Conditions.registerAll(); CommandRegistry.register(); + PoiManager.registerAll(); DataExchangeAPI.registerDescriptors(List.of( HelloClient.DESCRIPTOR, diff --git a/src/main/java/org/betterx/bclib/api/v2/poi/BCLPoiType.java b/src/main/java/org/betterx/bclib/api/v2/poi/BCLPoiType.java index c3a20620..1722b20e 100644 --- a/src/main/java/org/betterx/bclib/api/v2/poi/BCLPoiType.java +++ b/src/main/java/org/betterx/bclib/api/v2/poi/BCLPoiType.java @@ -1,14 +1,13 @@ package org.betterx.bclib.api.v2.poi; import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.TagKey; import net.minecraft.world.entity.ai.village.poi.PoiManager; import net.minecraft.world.entity.ai.village.poi.PoiRecord; import net.minecraft.world.entity.ai.village.poi.PoiType; -import net.minecraft.world.entity.ai.village.poi.PoiTypes; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; @@ -41,21 +40,14 @@ public class BCLPoiType { this.validRange = validRange; } - public static BCLPoiType register( - ResourceLocation location, - Set matchingStates, - int maxTickets, - int validRanges - ) { - ResourceKey key = ResourceKey.create(Registry.POINT_OF_INTEREST_TYPE_REGISTRY, location); - PoiType type = PoiTypes.register(Registry.POINT_OF_INTEREST_TYPE, key, matchingStates, maxTickets, validRanges); - return new BCLPoiType(key, type, matchingStates, maxTickets, validRanges); - } - public static Set getBlockStates(Block block) { return ImmutableSet.copyOf(block.getStateDefinition().getPossibleStates()); } + public void setTag(TagKey tag) { + org.betterx.bclib.api.v2.poi.PoiManager.setTag(type, tag); + } + public Optional findPoiAround( ServerLevel level, BlockPos center, @@ -105,4 +97,22 @@ public class BCLPoiType { return record.map(poiRecord -> poiRecord.getPos()); } + + /** + * @param location + * @param matchingStates + * @param maxTickets + * @param validRanges + * @return + * @deprecated Please use {@link org.betterx.bclib.api.v2.poi.PoiManager#register(ResourceLocation, Set, int, int)} instead + */ + @Deprecated(forRemoval = true) + public static BCLPoiType register( + ResourceLocation location, + Set matchingStates, + int maxTickets, + int validRanges + ) { + return org.betterx.bclib.api.v2.poi.PoiManager.register(location, matchingStates, maxTickets, validRanges); + } } diff --git a/src/main/java/org/betterx/bclib/api/v2/poi/PoiManager.java b/src/main/java/org/betterx/bclib/api/v2/poi/PoiManager.java new file mode 100644 index 00000000..59246925 --- /dev/null +++ b/src/main/java/org/betterx/bclib/api/v2/poi/PoiManager.java @@ -0,0 +1,35 @@ +package org.betterx.bclib.api.v2.poi; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.entity.ai.village.poi.PoiTypes; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; + +import java.util.Set; + +public class PoiManager { + public static BCLPoiType register( + ResourceLocation location, + Set matchingStates, + int maxTickets, + int validRanges + ) { + ResourceKey key = ResourceKey.create(Registry.POINT_OF_INTEREST_TYPE_REGISTRY, location); + PoiType type = PoiTypes.register(Registry.POINT_OF_INTEREST_TYPE, key, matchingStates, maxTickets, validRanges); + return new BCLPoiType(key, type, matchingStates, maxTickets, validRanges); + } + + public static void setTag(ResourceKey type, TagKey tag) { + setTag(Registry.POINT_OF_INTEREST_TYPE.get(type), tag); + } + + public static void setTag(PoiType type, TagKey tag) { + if ((Object) type instanceof PoiTypeExtension ext) { + ext.bcl_setTag(tag); + } + } +} diff --git a/src/main/java/org/betterx/bclib/api/v2/poi/PoiTypeExtension.java b/src/main/java/org/betterx/bclib/api/v2/poi/PoiTypeExtension.java new file mode 100644 index 00000000..ce591461 --- /dev/null +++ b/src/main/java/org/betterx/bclib/api/v2/poi/PoiTypeExtension.java @@ -0,0 +1,8 @@ +package org.betterx.bclib.api.v2.poi; + +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.block.Block; + +public interface PoiTypeExtension { + void bcl_setTag(TagKey tag); +} diff --git a/src/main/java/org/betterx/bclib/mixin/common/PoiTypeMixin.java b/src/main/java/org/betterx/bclib/mixin/common/PoiTypeMixin.java new file mode 100644 index 00000000..ab71318a --- /dev/null +++ b/src/main/java/org/betterx/bclib/mixin/common/PoiTypeMixin.java @@ -0,0 +1,29 @@ +package org.betterx.bclib.mixin.common; + +import org.betterx.bclib.api.v2.poi.PoiTypeExtension; + +import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.ai.village.poi.PoiType; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PoiType.class) +public class PoiTypeMixin implements PoiTypeExtension { + private TagKey bcl_tag = null; + + @Inject(method = "is", cancellable = true, at = @At("HEAD")) + void bcl_is(BlockState blockState, CallbackInfoReturnable cir) { + if (bcl_tag != null && blockState.is(bcl_tag)) { + cir.setReturnValue(true); + } + } + + public void bcl_setTag(TagKey tag) { + bcl_tag = tag; + } +} diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 538b02ed..be711062 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -25,6 +25,7 @@ "MobSpawnSettingsAccessor", "NoiseBasedChunkGeneratorMixin", "PistonBaseBlockMixin", + "PoiTypeMixin", "PortalShapeMixin", "PotionBrewingAccessor", "RecipeManagerAccessor",