Improve bed search pattern to go inwards out for bed search radius

This commit is contained in:
Aikar
2018-07-08 03:30:40 -04:00
parent 93dc25ecec
commit 20aba250df

View File

@@ -30,38 +30,73 @@ index 06c54690f..50416f40a 100644
+ } + }
} }
diff --git a/src/main/java/net/minecraft/server/BlockBed.java b/src/main/java/net/minecraft/server/BlockBed.java diff --git a/src/main/java/net/minecraft/server/BlockBed.java b/src/main/java/net/minecraft/server/BlockBed.java
index 9346bddff..b12834705 100644 index 9346bddff..f1a107991 100644
--- a/src/main/java/net/minecraft/server/BlockBed.java --- a/src/main/java/net/minecraft/server/BlockBed.java
+++ b/src/main/java/net/minecraft/server/BlockBed.java +++ b/src/main/java/net/minecraft/server/BlockBed.java
@@ -0,0 +0,0 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity { @@ -0,0 +0,0 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity {
int k1 = l - enumdirection.getAdjacentZ() * i1 - 1; @Nullable
int l1 = j1 + 2; public static BlockPosition a(World world, BlockPosition blockposition, int i) {
int i2 = k1 + 2; EnumDirection enumdirection = (EnumDirection) world.getType(blockposition).get(BlockBed.FACING);
- + // Paper - replace whole method
- for (int j2 = j1; j2 <= l1; ++j2) { + int radius = world.paperConfig.bedSearchRadius;
- for (int k2 = k1; k2 <= i2; ++k2) { + for (int r = 1; r <= radius; r++) {
- BlockPosition blockposition1 = new BlockPosition(j2, k, k2); + int x = -r;
+ // Paper start + int z = r;
+ int radius = world.paperConfig.bedSearchRadius - 1;
+ j1 -= radius;
+ k1 -= radius;
+ l1 += radius;
+ i2 += radius;
+ // Paper end
+ +
+ for (int j2 = j1 ; j2 <= l1 ; ++j2) { + // Iterates the edge of half of the box; then negates for other half.
+ for (int k2 = k1 ; k2 <= i2 ; ++k2) { for (int y = -radius ; y <= radius ; y++) { // Paper + while (x <= r && z > -r) {
+ BlockPosition blockposition1 = new BlockPosition(j2, k + y, k2); // Paper + for (int y = -1; y <= 1; y++) {
+ BlockPosition pos = blockposition.add(x, y, z);
if (b(world, blockposition1)) { + if (isSafeRespawn(world, pos)) {
if (i <= 0) { + if (i-- <= 0) {
+ return pos;
+ }
+ }
+ pos = blockposition.add(-x, y, -z);
+ if (isSafeRespawn(world, pos)) {
+ if (i-- <= 0) {
+ return pos;
+ }
+ }
+
+ pos = blockposition.add(enumdirection.getAdjacentX() + x, y, enumdirection.getAdjacentZ() + z);
+ if (isSafeRespawn(world, pos)) {
+ if (i-- <= 0) {
+ return pos;
+ }
+ }
+
+ pos = blockposition.add(enumdirection.getAdjacentX() - x, y, enumdirection.getAdjacentZ() - z);
+ if (isSafeRespawn(world, pos)) {
+ if (i-- <= 0) {
+ return pos;
+ }
+ }
+ }
+ if (x < r) {
+ x++;
+ } else {
+ z--;
+ }
+ }
+ }
+
+ return null; /* // Paper comment out
int j = blockposition.getX();
int k = blockposition.getY();
int l = blockposition.getZ();
@@ -0,0 +0,0 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity { @@ -0,0 +0,0 @@ public class BlockBed extends BlockFacingHorizontal implements ITileEntity {
}
--i;
- }
+ }} // Paper
}
} }
} }
- return null;
+ return null;*/ // Paper
}
+ protected static boolean isSafeRespawn(World world, BlockPosition blockposition) { // Paper - OBFHELPER + behavior improvement
+ return b(world, blockposition) && world.getType(blockposition.down()).getMaterial().isBuildable(); // Paper - ensure solid block
+ }
protected static boolean b(World world, BlockPosition blockposition) {
return world.getType(blockposition.down()).q() && !world.getType(blockposition).getMaterial().isBuildable() && !world.getType(blockposition.up()).getMaterial().isBuildable();
}
-- --