[Fix] Reduced Radius for Eternal Portal Search
This commit is contained in:
parent
8b845a0a8f
commit
1356a91e77
5 changed files with 102 additions and 54 deletions
|
@ -10,6 +10,7 @@ import org.betterx.bclib.api.v2.WorldDataAPI;
|
|||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.util.Logger;
|
||||
import org.betterx.betterend.api.BetterEndPlugin;
|
||||
import org.betterx.betterend.commands.CommandRegistry;
|
||||
import org.betterx.betterend.config.Configs;
|
||||
import org.betterx.betterend.effects.EndPotions;
|
||||
import org.betterx.betterend.integration.Integrations;
|
||||
|
@ -37,7 +38,6 @@ public class BetterEnd implements ModInitializer {
|
|||
EndEntities.register();
|
||||
EndBiomes.register();
|
||||
EndTags.register();
|
||||
EndPoiTypes.register();
|
||||
EndEnchantments.register();
|
||||
EndPotions.register();
|
||||
CraftingRecipes.register();
|
||||
|
@ -50,6 +50,7 @@ public class BetterEnd implements ModInitializer {
|
|||
BonemealPlants.init();
|
||||
GeneratorOptions.init();
|
||||
LootTableUtil.init();
|
||||
CommandRegistry.register();
|
||||
FabricLoader.getInstance()
|
||||
.getEntrypoints("betterend", BetterEndPlugin.class)
|
||||
.forEach(BetterEndPlugin::register);
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package org.betterx.betterend.commands;
|
||||
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandRegistry {
|
||||
public static void register() {
|
||||
CommandRegistrationCallback.EVENT.register(CommandRegistry::register);
|
||||
}
|
||||
|
||||
private static void register(CommandDispatcher<CommandSourceStack> dispatcher,
|
||||
CommandBuildContext commandBuildContext,
|
||||
Commands.CommandSelection commandSelection) {
|
||||
// dispatcher.register(
|
||||
// Commands.literal("be")
|
||||
// .requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||
// .then(Commands.literal("locate_portal")
|
||||
// .requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||
// .executes(ctx -> find_poi(ctx))
|
||||
// )
|
||||
// );
|
||||
}
|
||||
|
||||
private static final Map<Holder<Biome>, BlockState> biomeMap = new HashMap<>();
|
||||
private static int biomeMapIdx = 0;
|
||||
private static final BlockState[] states = {
|
||||
Blocks.RED_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.BLUE_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.YELLOW_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.LIME_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.PINK_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.GREEN_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.WHITE_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.BLACK_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.ORANGE_STAINED_GLASS.defaultBlockState(),
|
||||
Blocks.LIGHT_BLUE_STAINED_GLASS.defaultBlockState()
|
||||
};
|
||||
private static final BlockState[] states2 = {
|
||||
Blocks.RED_CONCRETE.defaultBlockState(),
|
||||
Blocks.BLUE_CONCRETE.defaultBlockState(),
|
||||
Blocks.YELLOW_CONCRETE.defaultBlockState(),
|
||||
Blocks.LIME_CONCRETE.defaultBlockState(),
|
||||
Blocks.PINK_CONCRETE.defaultBlockState(),
|
||||
Blocks.GREEN_CONCRETE.defaultBlockState(),
|
||||
Blocks.WHITE_CONCRETE.defaultBlockState(),
|
||||
Blocks.BLACK_CONCRETE.defaultBlockState(),
|
||||
Blocks.ORANGE_CONCRETE.defaultBlockState(),
|
||||
Blocks.LIGHT_BLUE_CONCRETE.defaultBlockState()
|
||||
};
|
||||
|
||||
|
||||
private static int find_poi(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -39,8 +39,12 @@ public class StoneMaterial {
|
|||
public final Block furnace;
|
||||
public final Block flowerPot;
|
||||
|
||||
public static FabricBlockSettings createMaterial(MaterialColor color) {
|
||||
return FabricBlockSettings.copyOf(Blocks.END_STONE).mapColor(color);
|
||||
}
|
||||
|
||||
public StoneMaterial(String name, MaterialColor color) {
|
||||
FabricBlockSettings material = FabricBlockSettings.copyOf(Blocks.END_STONE).mapColor(color);
|
||||
FabricBlockSettings material = createMaterial(color);
|
||||
|
||||
stone = EndBlocks.registerBlock(name, new BaseBlock(material));
|
||||
polished = EndBlocks.registerBlock(name + "_polished", new BaseBlock(material));
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package org.betterx.betterend.registry;
|
||||
|
||||
import org.betterx.bclib.api.v2.poi.BCLPoiType;
|
||||
import org.betterx.bclib.api.v2.poi.PoiRegistry;
|
||||
import org.betterx.bclib.blocks.BlockProperties;
|
||||
import org.betterx.betterend.BetterEnd;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EndPoiTypes {
|
||||
public static final BCLPoiType ETERNAL_PORTAL = PoiRegistry
|
||||
.register(
|
||||
BetterEnd.makeID("eternal_portal"),
|
||||
() -> BCLPoiType
|
||||
.getBlockStates(EndBlocks.FLAVOLITE_RUNED_ETERNAL)
|
||||
.stream().filter(state -> !state.getValue(BlockProperties.ACTIVE))
|
||||
.collect(Collectors.toSet()),
|
||||
0, 1
|
||||
);
|
||||
|
||||
private static void bootstrap() {
|
||||
//This basically ensures that our static structures are loaded and registered
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
PoiRegistry.registerForBootstrap(EndPoiTypes::bootstrap);
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiManager;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
@ -35,13 +36,11 @@ import org.betterx.betterend.blocks.RunedFlavolite;
|
|||
import org.betterx.betterend.blocks.entities.EternalPedestalEntity;
|
||||
import org.betterx.betterend.registry.EndBlocks;
|
||||
import org.betterx.betterend.registry.EndFeatures;
|
||||
import org.betterx.betterend.registry.EndPoiTypes;
|
||||
import org.betterx.betterend.registry.EndPortals;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -97,7 +96,7 @@ public class EternalRitual {
|
|||
private final static Block PORTAL = EndBlocks.END_PORTAL_BLOCK;
|
||||
private final static BooleanProperty ACTIVE = BlockProperties.ACTIVE;
|
||||
|
||||
public final static int SEARCH_RADIUS = calculateSearchSteps(48);
|
||||
public final static int SEARCH_RADIUS = calculateSearchSteps(16);
|
||||
|
||||
private Level world;
|
||||
private Direction.Axis axis;
|
||||
|
@ -366,28 +365,20 @@ public class EternalRitual {
|
|||
|
||||
@Nullable
|
||||
private BlockPos findFrame(ServerLevel level, BlockPos.MutableBlockPos startPos) {
|
||||
Optional<BlockPos> foundPos = EndPoiTypes
|
||||
.ETERNAL_PORTAL.findPoiAround(level, startPos, false, level.getWorldBorder());
|
||||
|
||||
if (foundPos.isPresent()) {
|
||||
if (checkFrame(world, foundPos.get())) {
|
||||
return foundPos.get();
|
||||
List<BlockPos.MutableBlockPos> foundPos = findAllBlockPos(
|
||||
level,
|
||||
startPos,
|
||||
(SEARCH_RADIUS >> 4) + 1,
|
||||
FRAME,
|
||||
blockState -> blockState.is(FRAME) && !blockState.getValue(ACTIVE)
|
||||
);
|
||||
for (BlockPos.MutableBlockPos testPos : foundPos) {
|
||||
if (checkFrame(level, testPos)) {
|
||||
return testPos;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
// List<BlockPos.MutableBlockPos> foundPos = findAllBlockPos(
|
||||
// world,
|
||||
// startPos,
|
||||
// (SEARCH_RADIUS >> 4) + 1,
|
||||
// FRAME,
|
||||
// blockState -> blockState.is(FRAME) && !blockState.getValue(ACTIVE)
|
||||
// );
|
||||
// for (BlockPos.MutableBlockPos testPos : foundPos) {
|
||||
// if (checkFrame(world, testPos)) {
|
||||
// return testPos;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
}
|
||||
|
||||
private BlockPos findPortalPos(int portalId) {
|
||||
|
@ -408,6 +399,7 @@ public class EternalRitual {
|
|||
}
|
||||
Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X;
|
||||
int worldCeil = targetWorld.getHeight() - 1;
|
||||
|
||||
if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
|
||||
generatePortal(targetWorld, basePos, portalAxis, portalId);
|
||||
return basePos.immutable();
|
||||
|
@ -415,6 +407,10 @@ public class EternalRitual {
|
|||
Direction direction = Direction.EAST;
|
||||
BlockPos.MutableBlockPos checkPos = basePos.mutable();
|
||||
int radius = (int) ((SEARCH_RADIUS / multiplier) + 1);
|
||||
//make sure chunks are properly loaded for faster searches
|
||||
PoiManager poiManager = targetWorld.getPoiManager();
|
||||
poiManager.ensureLoadedAndValid(world, checkPos, radius >> 4);
|
||||
|
||||
for (int step = 1; step < radius; step++) {
|
||||
for (int i = 0; i < (step >> 1); i++) {
|
||||
ChunkAccess chunk = targetWorld.getChunk(checkPos);
|
||||
|
@ -743,11 +739,14 @@ public class EternalRitual {
|
|||
* @param condition Predicate for test block states in the chunk section
|
||||
* @return List of positions of the all found blocks or empty list.
|
||||
*/
|
||||
public static List<BlockPos.MutableBlockPos> findAllBlockPos(Level world,
|
||||
public static List<BlockPos.MutableBlockPos> findAllBlockPos(ServerLevel world,
|
||||
BlockPos.MutableBlockPos checkPos,
|
||||
int radius,
|
||||
Block searchBlock,
|
||||
Predicate<BlockState> condition) {
|
||||
//make sure chunks are properly loaded for faster searches
|
||||
PoiManager poiManager = world.getPoiManager();
|
||||
poiManager.ensureLoadedAndValid(world, checkPos, radius >> 4);
|
||||
|
||||
List<BlockPos.MutableBlockPos> posFound = Lists.newArrayList();
|
||||
Direction moveDirection = Direction.EAST;
|
||||
|
@ -779,7 +778,7 @@ public class EternalRitual {
|
|||
return posFound;
|
||||
}
|
||||
|
||||
public static int calculateSearchSteps(int radius) {
|
||||
return radius * 4 - 1;
|
||||
public static int calculateSearchSteps(int chunkRadius) {
|
||||
return chunkRadius * 4 - 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue