[Changes] Use POIs to find portal in other dimension (#60)
This commit is contained in:
parent
fd7989cdd1
commit
7f10836a33
2 changed files with 27 additions and 42 deletions
|
@ -14,6 +14,12 @@ public class EndPoiTypes {
|
||||||
0, 1
|
0, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static final BCLPoiType ETERNAL_PORTAL_ACTIVE = PoiManager.register(
|
||||||
|
BetterEnd.makeID("eternal_portal_active"),
|
||||||
|
Set.of(EndBlocks.FLAVOLITE_RUNED_ETERNAL.defaultBlockState().setValue(RunedFlavolite.ACTIVATED, true)),
|
||||||
|
0, 1
|
||||||
|
);
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,9 @@ import net.minecraft.world.level.levelgen.Heightmap;
|
||||||
import net.minecraft.world.level.levelgen.LegacyRandomSource;
|
import net.minecraft.world.level.levelgen.LegacyRandomSource;
|
||||||
import net.minecraft.world.level.material.Material;
|
import net.minecraft.world.level.material.Material;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -730,6 +728,17 @@ public class EternalRitual {
|
||||||
Block searchBlock,
|
Block searchBlock,
|
||||||
Predicate<BlockState> condition
|
Predicate<BlockState> condition
|
||||||
) {
|
) {
|
||||||
|
if (world instanceof ServerLevel server) {
|
||||||
|
BlockPos.MutableBlockPos altCheckPos = new BlockPos.MutableBlockPos(
|
||||||
|
checkPos.getX(),
|
||||||
|
checkPos.getY(),
|
||||||
|
checkPos.getZ()
|
||||||
|
);
|
||||||
|
var pos = findClosestPoi(server, altCheckPos);
|
||||||
|
if (pos != null) {
|
||||||
|
checkPos = pos.mutable();
|
||||||
|
}
|
||||||
|
}
|
||||||
Direction moveDirection = Direction.EAST;
|
Direction moveDirection = Direction.EAST;
|
||||||
for (int step = 1; step < radius; step++) {
|
for (int step = 1; step < radius; step++) {
|
||||||
for (int i = 0; i < (step >> 1); i++) {
|
for (int i = 0; i < (step >> 1); i++) {
|
||||||
|
@ -752,7 +761,9 @@ public class EternalRitual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
System.out.print(checkPos + " -> " + moveDirection + " -> ");
|
||||||
checkPos.move(moveDirection, 16);
|
checkPos.move(moveDirection, 16);
|
||||||
|
System.out.println(checkPos);
|
||||||
}
|
}
|
||||||
moveDirection = moveDirection.getClockWise();
|
moveDirection = moveDirection.getClockWise();
|
||||||
}
|
}
|
||||||
|
@ -760,52 +771,20 @@ public class EternalRitual {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param world World for search
|
* @param world World for search
|
||||||
* @param checkPos Start search position
|
* @param checkPos Start search position
|
||||||
* @param radius Search radius
|
* @param radius Search radius
|
||||||
* @param searchBlock Target block
|
|
||||||
* @param condition Predicate for test block states in the chunk section
|
|
||||||
* @return List of positions of the all found blocks or empty list.
|
* @return List of positions of the all found blocks or empty list.
|
||||||
*/
|
*/
|
||||||
public static List<BlockPos.MutableBlockPos> findAllBlockPos(
|
public static BlockPos findClosestPoi(
|
||||||
ServerLevel world,
|
ServerLevel world,
|
||||||
BlockPos.MutableBlockPos checkPos,
|
BlockPos.MutableBlockPos checkPos
|
||||||
int radius,
|
|
||||||
Block searchBlock,
|
|
||||||
Predicate<BlockState> condition
|
|
||||||
) {
|
) {
|
||||||
//make sure chunks are properly loaded for faster searches
|
//make sure chunks are properly loaded for faster searches
|
||||||
PoiManager poiManager = world.getPoiManager();
|
PoiManager poiManager = world.getPoiManager();
|
||||||
poiManager.ensureLoadedAndValid(world, checkPos, radius >> 4);
|
poiManager.ensureLoadedAndValid(world, checkPos, 128);
|
||||||
|
return EndPoiTypes.ETERNAL_PORTAL_ACTIVE.findClosest(world, checkPos, 128)
|
||||||
List<BlockPos.MutableBlockPos> posFound = Lists.newArrayList();
|
.orElse(null);
|
||||||
Direction moveDirection = Direction.EAST;
|
|
||||||
for (int step = 1; step < radius; step++) {
|
|
||||||
for (int i = 0; i < (step >> 1); i++) {
|
|
||||||
ChunkAccess chunk = world.getChunk(checkPos);
|
|
||||||
if (!(chunk instanceof LevelChunk) || ((LevelChunk) chunk).isEmpty()) continue;
|
|
||||||
for (LevelChunkSection section : chunk.getSections()) {
|
|
||||||
if (section == null || !section.getStates().maybeHas(condition)) continue;
|
|
||||||
for (int x = 0; x < 16; x++) {
|
|
||||||
for (int y = 0; y < 16; y++) {
|
|
||||||
for (int z = 0; z < 16; z++) {
|
|
||||||
BlockState checkState = section.getBlockState(x, y, z);
|
|
||||||
if (checkState.is(searchBlock)) {
|
|
||||||
int worldX = (chunk.getPos().x << 4) + x;
|
|
||||||
int worldY = section.bottomBlockY() + y;
|
|
||||||
int worldZ = (chunk.getPos().z << 4) + z;
|
|
||||||
checkPos.set(worldX, worldY, worldZ);
|
|
||||||
posFound.add(checkPos.mutable());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkPos.move(moveDirection, 16);
|
|
||||||
}
|
|
||||||
moveDirection = moveDirection.getClockWise();
|
|
||||||
}
|
|
||||||
return posFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int calculateSearchSteps(int chunkRadius) {
|
public static int calculateSearchSteps(int chunkRadius) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue