Some changes to portal frame locator code
This commit is contained in:
parent
1356a91e77
commit
2eed66008a
4 changed files with 73 additions and 23 deletions
|
@ -34,6 +34,7 @@ public class BetterEnd implements ModInitializer {
|
|||
EndPortals.loadPortals();
|
||||
EndSounds.register();
|
||||
EndBlockEntities.register();
|
||||
EndPoiTypes.register();
|
||||
EndFeatures.register();
|
||||
EndEntities.register();
|
||||
EndBiomes.register();
|
||||
|
|
|
@ -3,10 +3,15 @@ package org.betterx.betterend.commands;
|
|||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
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.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
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.context.CommandContext;
|
||||
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.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CommandRegistry {
|
||||
public static void register() {
|
||||
|
@ -26,14 +35,14 @@ public class CommandRegistry {
|
|||
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))
|
||||
// )
|
||||
// );
|
||||
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, EndPoiTypes.ETERNAL_PORTAL_INACTIVE))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -36,11 +36,13 @@ 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;
|
||||
|
@ -96,7 +98,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(16);
|
||||
public final static int SEARCH_RADIUS = calculateSearchSteps(48);
|
||||
|
||||
private Level world;
|
||||
private Direction.Axis axis;
|
||||
|
@ -365,19 +367,26 @@ public class EternalRitual {
|
|||
|
||||
@Nullable
|
||||
private BlockPos findFrame(ServerLevel level, BlockPos.MutableBlockPos startPos) {
|
||||
|
||||
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;
|
||||
}
|
||||
Optional<BlockPos> found = EndPoiTypes.ETERNAL_PORTAL_INACTIVE.findPoiAround(level,
|
||||
startPos,
|
||||
SEARCH_RADIUS >> 4 + 1,
|
||||
level.getWorldBorder());
|
||||
if (found.isPresent()) {
|
||||
if (checkFrame(level, found.get()))
|
||||
return found.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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue