Some changes to portal frame locator code

This commit is contained in:
Frank 2022-06-08 17:37:23 +02:00
parent 1356a91e77
commit 2eed66008a
4 changed files with 73 additions and 23 deletions

View file

@ -34,6 +34,7 @@ public class BetterEnd implements ModInitializer {
EndPortals.loadPortals(); EndPortals.loadPortals();
EndSounds.register(); EndSounds.register();
EndBlockEntities.register(); EndBlockEntities.register();
EndPoiTypes.register();
EndFeatures.register(); EndFeatures.register();
EndEntities.register(); EndEntities.register();
EndBiomes.register(); EndBiomes.register();

View file

@ -3,10 +3,15 @@ package org.betterx.betterend.commands;
import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands; import net.minecraft.commands.Commands;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
@ -14,9 +19,13 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.betterx.bclib.api.v2.poi.BCLPoiType;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.betterend.registry.EndPoiTypes;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class CommandRegistry { public class CommandRegistry {
public static void register() { public static void register() {
@ -26,14 +35,14 @@ public class CommandRegistry {
private static void register(CommandDispatcher<CommandSourceStack> dispatcher, private static void register(CommandDispatcher<CommandSourceStack> dispatcher,
CommandBuildContext commandBuildContext, CommandBuildContext commandBuildContext,
Commands.CommandSelection commandSelection) { Commands.CommandSelection commandSelection) {
// dispatcher.register( dispatcher.register(
// Commands.literal("be") Commands.literal("be")
// .requires(source -> source.hasPermission(Commands.LEVEL_OWNERS)) .requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
// .then(Commands.literal("locate_portal") .then(Commands.literal("locate_portal")
// .requires(source -> source.hasPermission(Commands.LEVEL_OWNERS)) .requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
// .executes(ctx -> find_poi(ctx)) .executes(ctx -> find_poi(ctx, EndPoiTypes.ETERNAL_PORTAL_INACTIVE))
// ) )
// ); );
} }
private static final Map<Holder<Biome>, BlockState> biomeMap = new HashMap<>(); private static final Map<Holder<Biome>, BlockState> biomeMap = new HashMap<>();
@ -64,8 +73,21 @@ public class CommandRegistry {
}; };
private static int find_poi(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException { private static int find_poi(CommandContext<CommandSourceStack> ctx, BCLPoiType poi) throws CommandSyntaxException {
final CommandSourceStack source = ctx.getSource();
final ServerPlayer player = source.getPlayerOrException();
Vec3 pos = source.getPosition();
final ServerLevel level = source.getLevel();
MutableBlockPos mPos = new BlockPos(pos).mutable();
System.out.println("Searching POI: " + poi.key);
Optional<BlockPos> found = poi.findPoiAround(level, mPos, false, level.getWorldBorder());
System.out.println("Found at: " + found.orElse(null));
if (found.isPresent()) {
BlocksHelper.setWithoutUpdate(level, found.get(), Blocks.YELLOW_CONCRETE);
BlocksHelper.setWithoutUpdate(level, mPos, Blocks.LIGHT_BLUE_CONCRETE);
} else {
BlocksHelper.setWithoutUpdate(level, mPos, Blocks.RED_CONCRETE);
}
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
} }

View file

@ -0,0 +1,18 @@
package org.betterx.betterend.registry;
import org.betterx.bclib.api.v2.poi.BCLPoiType;
import org.betterx.betterend.BetterEnd;
import org.betterx.betterend.blocks.RunedFlavolite;
import java.util.Set;
public class EndPoiTypes {
public static final BCLPoiType ETERNAL_PORTAL_INACTIVE = BCLPoiType.register(
BetterEnd.makeID("eternal_portal_inactive"),
Set.of(EndBlocks.FLAVOLITE_RUNED_ETERNAL.defaultBlockState().setValue(RunedFlavolite.ACTIVATED, false)),
0, 1);
public static void register() {
}
}

View file

@ -36,11 +36,13 @@ import org.betterx.betterend.blocks.RunedFlavolite;
import org.betterx.betterend.blocks.entities.EternalPedestalEntity; import org.betterx.betterend.blocks.entities.EternalPedestalEntity;
import org.betterx.betterend.registry.EndBlocks; import org.betterx.betterend.registry.EndBlocks;
import org.betterx.betterend.registry.EndFeatures; import org.betterx.betterend.registry.EndFeatures;
import org.betterx.betterend.registry.EndPoiTypes;
import org.betterx.betterend.registry.EndPortals; import org.betterx.betterend.registry.EndPortals;
import java.awt.*; import java.awt.*;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -96,7 +98,7 @@ public class EternalRitual {
private final static Block PORTAL = EndBlocks.END_PORTAL_BLOCK; private final static Block PORTAL = EndBlocks.END_PORTAL_BLOCK;
private final static BooleanProperty ACTIVE = BlockProperties.ACTIVE; private final static BooleanProperty ACTIVE = BlockProperties.ACTIVE;
public final static int SEARCH_RADIUS = calculateSearchSteps(16); public final static int SEARCH_RADIUS = calculateSearchSteps(48);
private Level world; private Level world;
private Direction.Axis axis; private Direction.Axis axis;
@ -365,19 +367,26 @@ public class EternalRitual {
@Nullable @Nullable
private BlockPos findFrame(ServerLevel level, BlockPos.MutableBlockPos startPos) { private BlockPos findFrame(ServerLevel level, BlockPos.MutableBlockPos startPos) {
Optional<BlockPos> found = EndPoiTypes.ETERNAL_PORTAL_INACTIVE.findPoiAround(level,
List<BlockPos.MutableBlockPos> foundPos = findAllBlockPos(
level,
startPos, startPos,
(SEARCH_RADIUS >> 4) + 1, SEARCH_RADIUS >> 4 + 1,
FRAME, level.getWorldBorder());
blockState -> blockState.is(FRAME) && !blockState.getValue(ACTIVE) if (found.isPresent()) {
); if (checkFrame(level, found.get()))
for (BlockPos.MutableBlockPos testPos : foundPos) { return found.get();
if (checkFrame(level, testPos)) {
return testPos;
}
} }
// 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; return null;
} }