mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Added a general-use fuzz function
This commit is contained in:
parent
fd7848e8e5
commit
06954aa779
1 changed files with 22 additions and 1 deletions
|
@ -1,7 +1,10 @@
|
|||
package com.minelittlepony.unicopia.entity.player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.effect.SunBlindnessStatusEffect;
|
||||
|
||||
import net.minecraft.entity.ai.FuzzyPositions;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.SpawnLocating;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
@ -10,6 +13,24 @@ import net.minecraft.util.math.random.Random;
|
|||
|
||||
public class SpawnLocator extends SpawnLocating {
|
||||
|
||||
public static BlockPos findSafeSpawnLocation(ServerWorld world, int x, int z) {
|
||||
return SpawnLocating.findOverworldSpawn(world, x, z);
|
||||
}
|
||||
|
||||
public static Optional<BlockPos> fuzz(ServerWorld world, BlockPos pos, int horizontal, int vertical) {
|
||||
|
||||
for (int attempt = 0; attempt < 6; attempt++) {
|
||||
BlockPos target = FuzzyPositions.localFuzz(world.random, horizontal, vertical);
|
||||
target = findSafeSpawnLocation(world, target.getX(), target.getZ());
|
||||
|
||||
if (target != null) {
|
||||
return Optional.of(target);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static void selectSpawnPosition(ServerWorld world, PlayerEntity entity) {
|
||||
BlockPos spawnPos = world.getSpawnPos();
|
||||
int spawnRadius = Math.min(
|
||||
|
@ -30,7 +51,7 @@ public class SpawnLocator extends SpawnLocating {
|
|||
int x = tile % (spawnRadius * 2 + 1);
|
||||
int z = tile / (spawnRadius * 2 + 1);
|
||||
|
||||
BlockPos candidatePos = findOverworldSpawn(world,
|
||||
BlockPos candidatePos = findSafeSpawnLocation(world,
|
||||
spawnPos.getX() + x - spawnRadius,
|
||||
spawnPos.getZ() + z - spawnRadius
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue