[Fix] Reduced Radius for Eternal Portal Search
This commit is contained in:
parent
c87175159b
commit
74f4708196
5 changed files with 2 additions and 175 deletions
|
@ -74,7 +74,8 @@ public class WorldDataAPI {
|
|||
* @param modID - {@link String} modID.
|
||||
*/
|
||||
public static void registerModCache(String modID) {
|
||||
MODS.add(modID);
|
||||
if (MODS.contains(modID))
|
||||
MODS.add(modID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
package org.betterx.bclib.api.v2.poi;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
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.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;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BCLPoiType {
|
||||
public final ResourceKey<PoiType> key;
|
||||
public final Supplier<Set<BlockState>> matchingStatesProvider;
|
||||
public final int maxTickets;
|
||||
public final int validRange;
|
||||
|
||||
public BCLPoiType(ResourceKey<PoiType> key,
|
||||
Supplier<Set<BlockState>> matchingStatesProvider,
|
||||
int maxTickets,
|
||||
int validRange) {
|
||||
this.key = key;
|
||||
this.matchingStatesProvider = matchingStatesProvider;
|
||||
this.maxTickets = maxTickets;
|
||||
this.validRange = validRange;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
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.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PoiRegistry {
|
||||
@FunctionalInterface
|
||||
public interface OnBootstrap {
|
||||
void run();
|
||||
}
|
||||
|
||||
private final static List<BCLPoiType> KNOWN_TYPES = new ArrayList<>(4);
|
||||
private final static List<OnBootstrap> KNOW = new ArrayList<>(4);
|
||||
|
||||
public static void registerForBootstrap(OnBootstrap callback) {
|
||||
KNOW.add(callback);
|
||||
}
|
||||
|
||||
public static BCLPoiType register(ResourceLocation location,
|
||||
Supplier<Set<BlockState>> supplier,
|
||||
int maxTickets,
|
||||
int validRange) {
|
||||
ResourceKey<PoiType> key = ResourceKey.create(Registry.POINT_OF_INTEREST_TYPE_REGISTRY, location);
|
||||
|
||||
BCLPoiType type = new BCLPoiType(key, supplier, maxTickets, validRange);
|
||||
KNOWN_TYPES.add(type);
|
||||
return type;
|
||||
}
|
||||
|
||||
public static List<BCLPoiType> getCustomPOIs() {
|
||||
for (OnBootstrap bootstrap : KNOW) bootstrap.run();
|
||||
return ImmutableList.copyOf(KNOWN_TYPES);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import org.betterx.bclib.api.v2.poi.BCLPoiType;
|
||||
import org.betterx.bclib.api.v2.poi.PoiRegistry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Mixin(PoiTypes.class)
|
||||
public abstract class PoiTypesMixin {
|
||||
|
||||
@Shadow
|
||||
protected static PoiType register(Registry<PoiType> registry,
|
||||
ResourceKey<PoiType> resourceKey,
|
||||
Set<BlockState> set,
|
||||
int i,
|
||||
int j) {
|
||||
throw new RuntimeException("Just a Shadow.");
|
||||
}
|
||||
|
||||
@Shadow
|
||||
protected static void registerBlockStates(Holder<PoiType> holder) {
|
||||
throw new RuntimeException("Just a Shadow.");
|
||||
}
|
||||
|
||||
@Inject(method = "bootstrap", at = @At(value = "HEAD"))
|
||||
private static void bcl_bootstrap(Registry<PoiType> registry, CallbackInfoReturnable<PoiType> cir) {
|
||||
List<BCLPoiType> list = PoiRegistry.getCustomPOIs();
|
||||
for (BCLPoiType type : list) {
|
||||
register(registry, type.key, type.matchingStatesProvider.get(), type.maxTickets, type.validRange);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,6 @@
|
|||
"NoiseBasedChunkGeneratorMixin",
|
||||
"NoiseGeneratorSettingsMixin",
|
||||
"PistonBaseBlockMixin",
|
||||
"PoiTypesMixin",
|
||||
"PortalShapeMixin",
|
||||
"PotionBrewingAccessor",
|
||||
"PresetEditorMixin",
|
||||
|
|
Loading…
Reference in a new issue