mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Prevent suffocation while using /rtp (#445)
* rtp: check for suffocation before teleport * safety resolvers: teleport to middle of block * rtp: Fix negative coordinates being off by one * unsafe blocks: add campfires and magma * unsafe blocks: deduplicate block id formatting
This commit is contained in:
1 parent
377e46ff92
commit
771c16ed1a
6 files changed
+118
-26
No files matched your search
@@ -71,15 +71,36 @@ public interface FabricSafetyResolver extends SafetyResolver {
|
||||
for (int x = -SEARCH_RADIUS; x <= SEARCH_RADIUS; x++) {
|
||||
for (int z = -SEARCH_RADIUS; z <= SEARCH_RADIUS; z++) {
|
||||
blockPos.set(location.getX() + x, location.getY(), location.getZ() + z);
|
||||
final int highestY = getHighestYAt(world, blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
final int highestY = getHighestYAt(world, blockPos.getX(), blockPos.getY(), blockPos.getZ()) + 1;
|
||||
|
||||
final Block block = world.getBlockState(blockPos.withY(highestY)).getBlock();
|
||||
final Block block = world.getBlockState(blockPos.withY(highestY - 1)).getBlock();
|
||||
final Identifier id = Registries.BLOCK.getId(block);
|
||||
if (!(block instanceof FluidBlock) && !(block instanceof FireBlock) && isBlockSafe(id.toString())) {
|
||||
|
||||
final Block bodyBlockType = world.getBlockState(blockPos.withY(highestY)).getBlock();
|
||||
final Identifier bodyBlockId = Registries.BLOCK.getId(bodyBlockType);
|
||||
|
||||
final Block headBlockType = world.getBlockState(blockPos.withY(highestY + 1)).getBlock();
|
||||
final Identifier headBlockId = Registries.BLOCK.getId(headBlockType);
|
||||
|
||||
if (!(block instanceof FluidBlock) && !(block instanceof FireBlock) && isBlockSafeForStanding(id.toString())
|
||||
&& isBlockSafeForOccupation(bodyBlockId.toString())
|
||||
&& isBlockSafeForOccupation(headBlockId.toString())) {
|
||||
double locx = Math.floor(blockPos.getX());
|
||||
if (locx < 0) {
|
||||
locx += 1.5d;
|
||||
} else {
|
||||
locx = locx + 0.5d;
|
||||
}
|
||||
double locz = Math.floor(blockPos.getZ());
|
||||
if (locz < 0) {
|
||||
locz += 1.5d;
|
||||
} else {
|
||||
locz = locz + 0.5d;
|
||||
}
|
||||
return Optional.of(Location.at(
|
||||
blockPos.getX() + 0.5,
|
||||
highestY + 1,
|
||||
blockPos.getZ() + 0.5,
|
||||
locx,
|
||||
highestY,
|
||||
locz,
|
||||
location.getWorld()
|
||||
));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user