New Attempt at poi API

This commit is contained in:
Frank 2022-06-08 17:23:15 +02:00
parent 74f4708196
commit f06bf41fa4
3 changed files with 116 additions and 8 deletions

View file

@ -1,6 +1,11 @@
package org.betterx.bclib;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
import net.minecraft.world.level.block.Blocks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
@ -27,6 +32,7 @@ import org.betterx.bclib.registry.BaseRegistry;
import org.betterx.bclib.util.Logger;
import java.util.List;
import java.util.Set;
public class BCLib implements ModInitializer {
public static final String MOD_ID = "bclib";
@ -52,18 +58,21 @@ public class BCLib implements ModInitializer {
CommandRegistry.register();
DataExchangeAPI.registerDescriptors(List.of(
HelloClient.DESCRIPTOR,
HelloServer.DESCRIPTOR,
RequestFiles.DESCRIPTOR,
SendFiles.DESCRIPTOR,
Chunker.DESCRIPTOR
)
);
HelloClient.DESCRIPTOR,
HelloServer.DESCRIPTOR,
RequestFiles.DESCRIPTOR,
SendFiles.DESCRIPTOR,
Chunker.DESCRIPTOR
)
);
BCLibPatch.register();
TemplatePiece.ensureStaticInitialization();
PlacementModifiers.ensureStaticInitialization();
Configs.save();
ResourceKey<PoiType> key = ResourceKey.create(Registry.POINT_OF_INTEREST_TYPE_REGISTRY, makeID("test"));
PoiTypes.register(Registry.POINT_OF_INTEREST_TYPE, key, Set.of(Blocks.RED_CONCRETE.defaultBlockState()), 0, 1);
/*if (isDevEnvironment()) {
Biome.BiomeBuilder builder = new Biome.BiomeBuilder()
.precipitation(Biome.Precipitation.NONE)

View file

@ -0,0 +1,98 @@
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.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;
import net.minecraft.world.level.border.WorldBorder;
import com.google.common.collect.ImmutableSet;
import java.util.Comparator;
import java.util.Optional;
import java.util.Set;
public class BCLPoiType {
public final ResourceKey<PoiType> key;
public final PoiType type;
public final Set<BlockState> matchingStates;
public final int maxTickets;
public final int validRange;
public BCLPoiType(ResourceKey<PoiType> key,
PoiType type,
Set<BlockState> matchingStates,
int maxTickets,
int validRange) {
this.key = key;
this.type = type;
this.matchingStates = matchingStates;
this.maxTickets = maxTickets;
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) {
return ImmutableSet.copyOf(block.getStateDefinition().getPossibleStates());
}
public Optional<BlockPos> findPoiAround(ServerLevel level,
BlockPos center,
boolean wideSearch,
WorldBorder worldBorder) {
return findPoiAround(key, level, center, wideSearch, worldBorder);
}
public Optional<BlockPos> findPoiAround(ServerLevel level,
BlockPos center,
int radius,
WorldBorder worldBorder) {
return findPoiAround(key, level, center, radius, worldBorder);
}
public static Optional<BlockPos> findPoiAround(
ResourceKey<PoiType> key,
ServerLevel level,
BlockPos center,
boolean wideSearch,
WorldBorder worldBorder) {
return findPoiAround(key, level, center, wideSearch ? 16 : 128, worldBorder);
}
public static Optional<BlockPos> findPoiAround(
ResourceKey<PoiType> key,
ServerLevel level,
BlockPos center,
int radius,
WorldBorder worldBorder) {
PoiManager poiManager = level.getPoiManager();
poiManager.ensureLoadedAndValid(level, center, radius);
Optional<PoiRecord> record = poiManager
.getInSquare(holder -> holder.is(key), center, radius, PoiManager.Occupancy.ANY)
.filter(poiRecord -> worldBorder.isWithinBounds(poiRecord.getPos()))
.sorted(Comparator.<PoiRecord>comparingDouble(poiRecord -> poiRecord.getPos().distSqr(center))
.thenComparingInt(poiRecord -> poiRecord.getPos().getY()))
.filter(poiRecord -> level.getBlockState(poiRecord.getPos())
.hasProperty(BlockStateProperties.HORIZONTAL_AXIS))
.findFirst();
return record.map(poiRecord -> poiRecord.getPos());
}
}

View file

@ -13,4 +13,5 @@ extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
#Methods
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$Updater;)V
accessible method net/minecraft/world/level/storage/loot/LootPool <init> ([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;)V
accessible method net/minecraft/world/level/storage/loot/LootPool <init> ([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;)V
accessible method net/minecraft/world/entity/ai/village/poi/PoiTypes register (Lnet/minecraft/core/Registry;Lnet/minecraft/resources/ResourceKey;Ljava/util/Set;II)Lnet/minecraft/world/entity/ai/village/poi/PoiType;