[Feature] Identify POI by BlockTags
This commit is contained in:
parent
c622afc549
commit
5ac1eed54e
6 changed files with 98 additions and 13 deletions
|
@ -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.biomes.BiomeAPI;
|
||||||
import org.betterx.bclib.api.v2.levelgen.structures.TemplatePiece;
|
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.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.blockpredicates.BlockPredicates;
|
||||||
import org.betterx.bclib.api.v3.levelgen.features.placement.PlacementModifiers;
|
import org.betterx.bclib.api.v3.levelgen.features.placement.PlacementModifiers;
|
||||||
import org.betterx.bclib.commands.CommandRegistry;
|
import org.betterx.bclib.commands.CommandRegistry;
|
||||||
|
@ -61,6 +62,7 @@ public class BCLib implements ModInitializer {
|
||||||
AnvilRecipe.register();
|
AnvilRecipe.register();
|
||||||
Conditions.registerAll();
|
Conditions.registerAll();
|
||||||
CommandRegistry.register();
|
CommandRegistry.register();
|
||||||
|
PoiManager.registerAll();
|
||||||
|
|
||||||
DataExchangeAPI.registerDescriptors(List.of(
|
DataExchangeAPI.registerDescriptors(List.of(
|
||||||
HelloClient.DESCRIPTOR,
|
HelloClient.DESCRIPTOR,
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package org.betterx.bclib.api.v2.poi;
|
package org.betterx.bclib.api.v2.poi;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
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.PoiManager;
|
||||||
import net.minecraft.world.entity.ai.village.poi.PoiRecord;
|
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.PoiType;
|
||||||
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
@ -41,21 +40,14 @@ public class BCLPoiType {
|
||||||
this.validRange = validRange;
|
this.validRange = validRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BCLPoiType register(
|
|
||||||
ResourceLocation location,
|
|
||||||
Set<BlockState> matchingStates,
|
|
||||||
int maxTickets,
|
|
||||||
int validRanges
|
|
||||||
) {
|
|
||||||
ResourceKey<PoiType> 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<BlockState> getBlockStates(Block block) {
|
public static Set<BlockState> getBlockStates(Block block) {
|
||||||
return ImmutableSet.copyOf(block.getStateDefinition().getPossibleStates());
|
return ImmutableSet.copyOf(block.getStateDefinition().getPossibleStates());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTag(TagKey<Block> tag) {
|
||||||
|
org.betterx.bclib.api.v2.poi.PoiManager.setTag(type, tag);
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<BlockPos> findPoiAround(
|
public Optional<BlockPos> findPoiAround(
|
||||||
ServerLevel level,
|
ServerLevel level,
|
||||||
BlockPos center,
|
BlockPos center,
|
||||||
|
@ -105,4 +97,22 @@ public class BCLPoiType {
|
||||||
|
|
||||||
return record.map(poiRecord -> poiRecord.getPos());
|
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<BlockState> matchingStates,
|
||||||
|
int maxTickets,
|
||||||
|
int validRanges
|
||||||
|
) {
|
||||||
|
return org.betterx.bclib.api.v2.poi.PoiManager.register(location, matchingStates, maxTickets, validRanges);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
35
src/main/java/org/betterx/bclib/api/v2/poi/PoiManager.java
Normal file
35
src/main/java/org/betterx/bclib/api/v2/poi/PoiManager.java
Normal file
|
@ -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<BlockState> matchingStates,
|
||||||
|
int maxTickets,
|
||||||
|
int validRanges
|
||||||
|
) {
|
||||||
|
ResourceKey<PoiType> 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<PoiType> type, TagKey<Block> tag) {
|
||||||
|
setTag(Registry.POINT_OF_INTEREST_TYPE.get(type), tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setTag(PoiType type, TagKey<Block> tag) {
|
||||||
|
if ((Object) type instanceof PoiTypeExtension ext) {
|
||||||
|
ext.bcl_setTag(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Block> tag);
|
||||||
|
}
|
|
@ -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<Block> bcl_tag = null;
|
||||||
|
|
||||||
|
@Inject(method = "is", cancellable = true, at = @At("HEAD"))
|
||||||
|
void bcl_is(BlockState blockState, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (bcl_tag != null && blockState.is(bcl_tag)) {
|
||||||
|
cir.setReturnValue(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bcl_setTag(TagKey<Block> tag) {
|
||||||
|
bcl_tag = tag;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,7 @@
|
||||||
"MobSpawnSettingsAccessor",
|
"MobSpawnSettingsAccessor",
|
||||||
"NoiseBasedChunkGeneratorMixin",
|
"NoiseBasedChunkGeneratorMixin",
|
||||||
"PistonBaseBlockMixin",
|
"PistonBaseBlockMixin",
|
||||||
|
"PoiTypeMixin",
|
||||||
"PortalShapeMixin",
|
"PortalShapeMixin",
|
||||||
"PotionBrewingAccessor",
|
"PotionBrewingAccessor",
|
||||||
"RecipeManagerAccessor",
|
"RecipeManagerAccessor",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue