Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.LightType;
import net.minecraft.world.World;
Expand Down Expand Up @@ -336,13 +337,21 @@ public static boolean isValidSpawnBlock(BlockState blockState) {

// Finds the best block direction to get when interacting with the block.
public static Direction getDirection(BlockPos pos) {
Vec3d eyesPos = new Vec3d(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
if ((double) pos.getY() > eyesPos.y) {
if (mc.world.getBlockState(pos.add(0, -1, 0)).isReplaceable()) return Direction.DOWN;
else return mc.player.getHorizontalFacing().getOpposite();
double eyePos = mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose());
VoxelShape outline = mc.world.getBlockState(pos).getCollisionShape(mc.world, pos);
if (eyePos > pos.getY() + outline.getMax(Direction.Axis.Y) && mc.world.getBlockState(pos.add(0, 1, 0)).isReplaceable()) {
return Direction.UP;
} else if (eyePos < pos.getY() + outline.getMin(Direction.Axis.Y) && mc.world.getBlockState(pos.add(0, -1, 0)).isReplaceable()) {
return Direction.DOWN;
} else {
BlockPos difference = pos.subtract(mc.player.getBlockPos());

if (Math.abs(difference.getX()) > Math.abs(difference.getZ())) {
return difference.getX() > 0 ? Direction.WEST : Direction.EAST;
} else {
return difference.getZ() > 0 ? Direction.NORTH : Direction.SOUTH;
}
}
if (!mc.world.getBlockState(pos.add(0, 1, 0)).isReplaceable()) return mc.player.getHorizontalFacing().getOpposite();
return Direction.UP;
}

public enum MobSpawn {
Expand Down